The distance field is the right thing to use in this case. I think the cause of jaggedness with watershed outputs is likely to be casting that produces ties in the control function.<br><br>The jaggedness in my new method is a bug though. It definitely shouldn&#39;t be there as there aren&#39;t large plateau areas in the underlying distance function<br>
<br><div class="gmail_quote">On Thu, Feb 14, 2013 at 2:54 PM, Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hello I ran the following commands in SimpleITK with the attached output:<div><br></div><div><div>img = sitk.ReadImage( &quot;/Users/blowekamp/Downloads/image2D.png&quot; )</div><div>img = sitk.VectorIndexSelectionCast( img , 0 )</div>
<div>ws = sitk.MorphologicalWatershed( img )</div><div><br></div><div><div style="margin:0px;font-size:12px"><img alt="unknown.png" src="cid:1A418824-5E2B-4895-AA4E-D6376FCD14B8" height="465" width="215"></div></div><div>
<br></div><div><br></div><div>These are the default arguments for the morphological watershed function:</div><div><br></div><div><pre style="vertical-align:baseline;line-height:15px;font:inherit;white-space:pre-wrap;margin-bottom:0px;font-family:monospace,sans-serif;margin-top:0px;border:0px;padding:0px">
Image itk::simple::MorphologicalWatershed(const Image &amp;image1, double level=0.0, bool markWatershedLine=true,
bool fullyConnected=false)</pre><div><br></div></div><div>I am suspicious there there is some integer type used for a distance filed someplace in your code or other subtle misuse. Also I have generally plug a gradient image into the classic itk::WatershedImagefilter and not a distance filed.</div>
<div><br></div><div>Brad</div><div><br></div><div><div><div class="h5"><div>On Feb 13, 2013, at 7:19 PM, Dženan Zukić &lt;<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>&gt; wrote:</div><br></div>
</div><blockquote type="cite"><div><div class="h5"><div dir="ltr"><font><font face="verdana,sans-serif">I also suspected that at first, but the deviations are a lot bigger than what can be explained by discretization. Also, this should not be that much a problem for float images, but problem appears there as well. Most importantly of all, detected watershed lines do not lie where visual inspection expects them to be. One one slice I examined, the watershed line was shifted about 10 voxels!</font></font></div>


<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 13, 2013 at 6:35 PM, Richard Beare <span dir="ltr">&lt;<a href="mailto:richard.beare@gmail.com" target="_blank">richard.beare@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I&#39;ll attempt to check this out over the next couple of days.<br>
<br>
I suspect that you have run into issues with discrete nature of<br>
images, rather than a bug as such. Suppose that you are applying a<br>
watershed to a flat control surface. If the seed points are an odd<br>
number of voxels apart, and you chose the algorithm marking the<br>
watershed line, then the split will appear nicely down the middle. If<br>
you don&#39;t chose to mark the line then there will be a probably random<br>
choice of which voxels along the midpoint get assigned to which<br>
region. Conversely, if the seeds are an even number of voxels apart<br>
and you chose to mark the watershed line, then the line should lie<br>
between the pixels, but it can&#39;t. Hence it is likely to be jaggedly<br>
jumping between the two sides of the plateau. Similar things can<br>
happen with distance map control functions, as adjacent voxels can be<br>
equidistant from seeds, producing a plateau.<br>
<div><div><br>
<br>
On Thu, Feb 14, 2013 at 9:13 AM, Dženan Zukić &lt;<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>&gt; wrote:<br>
&gt; I think I have discovered a bug in WatershedImageFilter. Below is MWE which<br>
&gt; reproduces the problem. Input, output and expected image attached.<br>
&gt;<br>
&gt; The problem is that watershed lines are wrongly placed and rough (see<br>
&gt; attached error highlights). I first discovered it while working with 3D<br>
&gt; images, where the problem is more pronounced. I can also supply 3D float<br>
&gt; images (1.3MB). MorphologicalWatershedFromMarkersImageFilter suffers from<br>
&gt; the same problem.<br>
&gt;<br>
&gt; #include &lt;itkImageFileReader.h&gt;<br>
&gt; #include &lt;itkImageFileWriter.h&gt;<br>
&gt; #include &lt;itkWatershedImageFilter.h&gt;<br>
&gt; #include &lt;itkCastImageFilter.h&gt;<br>
&gt;<br>
&gt; typedef itk::Image&lt;unsigned char, 2&gt; VisualizingImageType;<br>
&gt;<br>
&gt; void main()<br>
&gt; {<br>
&gt;     typedef itk::ImageFileReader&lt;VisualizingImageType&gt; rType;<br>
&gt;     rType::Pointer reader=rType::New();<br>
&gt;     reader-&gt;SetFileName(&quot;image2D.png&quot;);<br>
&gt;     reader-&gt;Update();<br>
&gt;     VisualizingImageType::Pointer dm=reader-&gt;GetOutput();<br>
&gt;     typedef itk::WatershedImageFilter&lt;VisualizingImageType&gt; wsType;<br>
&gt;     wsType::Pointer ws2=wsType::New();<br>
&gt;     ws2-&gt;SetThreshold(0);<br>
&gt;     ws2-&gt;SetLevel(0);<br>
&gt;     ws2-&gt;SetInput(dm);<br>
&gt;     ws2-&gt;Update();<br>
&gt;     typedef itk::CastImageFilter&lt;wsType::OutputImageType,<br>
&gt; VisualizingImageType&gt; castType;<br>
&gt;     castType::Pointer caster=castType::New();<br>
&gt;     caster-&gt;SetInput(ws2-&gt;GetOutput());<br>
&gt;     caster-&gt;Update();<br>
&gt;     typedef itk::ImageFileWriter&lt;VisualizingImageType&gt; wType;<br>
&gt;     wType::Pointer writer=wType::New();<br>
&gt;     writer-&gt;SetFileName(&quot;imageWSint.png&quot;);<br>
&gt;     writer-&gt;SetInput(caster-&gt;GetOutput());<br>
&gt;     writer-&gt;Update();<br>
&gt; }<br>
</div></div></blockquote></div><br></div></div></div>
_____________________________________<br>Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>Kitware offers ITK Training Courses, for more information visit:<br><a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br><br>Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div></div></blockquote></div><br>