<br>Hi Christian,<br><br>Thanks for letting us know that the code works for you.<br><br>You really need a RescaleIntensityFilter.<br><br>The CastImageFilter will not do the trick here.<br><br>The distance image (in pixel type double) has a <br>
dynamic range equal to<br><br>                -7.28     to   79.209<br><br>If you just attempt to cast it to an unsigned char<br>image, the negative values will roll over and <br>they will become <br><br>  -7   ------&gt;  249<br>
  -6   ------&gt;  250<br>  -5   ------&gt;  251<br>  -4   ------&gt;  252<br>  -3   ------&gt;  253<br>  -2   ------&gt;  254<br>  -1  -------&gt;  255<br><br><br>Note also that in a general case you distances<br>could easily be larger than 255, and in such <br>
cases the value will also roll over to the low<br>values, as in<br><br>     256 -----&gt;  1<br>     257 -----&gt;  2<br>
     258 -----&gt;  3<br>     259 -----&gt;  4<br>
<br>...<br><br>another option that you may want to consider is the <br>ShiftScale image filter, with a <br><br>            scale of 1.0 and a <br>            shift of 0.0<br><br>This filter will truncate the values that outside the<br>
range of the output image.<br><br>Note that you still need to use a &quot;signed&quot; type for<br>the output pixel type, and that most of the basic<br>image file formats such as TIFF, JPEG and PNG<br>do not support signed integers.<br>
<br>In short, you may want to keep using the MetaImage<br>file format and the original double pixel type.<br><br><br>      Regards,<br><br><br>             Luis<br><br><br>--------------------------------------------------------------------------<br>
<div class="gmail_quote">On Sun, Apr 25, 2010 at 2:01 PM, Christian Werner <span dir="ltr">&lt;<a href="mailto:christian.werner@rwth-aachen.de">christian.werner@rwth-aachen.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thank you very much. That double datatype turned out to be the reason for all the trouble I had. Your code works perfectly.<br>
<br>
What I am trying now is to replace the Rescaling with a simple conversion because I need the real distance in pixels, unscaled. I tried itkCastImage but that yields bad results, maybe because the Maurer Filter produces negative values...? You already have funny behaviour if you just replace the Rescaler with a Caster in your code and with my image. &quot;Funny&quot; but still somehow right. However, if I am doing this on my volume data, where I actually need it for, it goes completely useless. (with the rescaling I have good results on my volume, too)<br>

<br>
Any idea?<br>
<br>
<br>
<br>
Luis Ibanez wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
<br>
Hi Christian,<br>
<br>
<br>
As described in the Insight Journal paper:<br>
<br>
&quot;N-D Linear Time Exact Signed Euclidean Distance Transform&quot;<br>
Tustison N.J., Siqueira M., Gee J.C.<br>
University of Pennsylvania<br>
<a href="http://www.insight-journal.org/browse/publication/77" target="_blank">http://www.insight-journal.org/browse/publication/77</a><br>
<a href="http://hdl.handle.net/1926/171" target="_blank">http://hdl.handle.net/1926/171</a><br>
<br>
<br>
where the ITK implementation of the Maurer filter was<br>
introduced,<br>
<br>
<br>
The Maurer filter computes the exact euclidean distance<br>
(down to numerical precision), while the Danielsson<br>
distance filter only approximates the distance up to a<br>
1 pixel spacing values.<br>
<br>
<br>
It is therefore, not surprising that you find differences<br>
between the distance values reported by these two<br>
filters....<br>
<br>
However, the output that you are reporting for the<br>
Signed Maurer distance really looks plain wrong     :-(<br>
<br>
<br>
It would seem that you have a problem in the<br>
instantiation of the filter.<br>
<br>
<br>
I just ran the Signed Maurer from a modified version<br>
of the Test in<br>
<br>
        Insight/Testing/Code/BasicFilters<br>
<br>
and using your input image (BTW: Thanks a lot for<br>
providing the input image and output images, that<br>
makes things a lot easier)  and it works fine for me.<br>
<br>
<br>
Please find attached to this email the source<br>
code that I used, and the output that I get from<br>
the rescaled distance.  <br>
<br>
Note that the distance is produced as an image<br>
of pixel type double, so the command line that<br>
I used was:<br>
<br>
<br>
MaurerDistance input_image.png distance.mha \<br>
maurer_output_uchar.png<br>
<br>
The exact distances are stored in the distance.mha<br>
file ( the MetaImage file format supports pixel type<br>
&quot;double&quot;), while the .png image holds a rescaled<br>
version of the distance, that is just intended for<br>
visualization (that rescaled one is the one attached<br>
to this email).<br>
<br>
I had to pass the .png file through GIMP in order<br>
to compress it further as a jpg file, to be able to<br>
attach it to this email. The mailing list restricts<br>
email size to 40Kb.<br>
<br>
--<br>
<br>
Please note also the setting of the filter:<br>
<br>
  filter-&gt;SetSquaredDistance( false );<br>
  filter-&gt;SetUseImageSpacing( false );<br>
  filter-&gt;SetInsideIsPositive( false );<br>
<br>
<br>
Please give it a try at this code and let us know<br>
if you find any problem.<br>
<br>
<br>
     Thanks<br>
<br>
<br>
          Luis<br>
<br>
<br>
-----------------------------------------------------------------------------------<br></div></div><div class="im">
On Sun, Apr 25, 2010 at 11:58 AM, Christian Werner &lt;<a href="mailto:christian.werner@rwth-aachen.de" target="_blank">christian.werner@rwth-aachen.de</a> &lt;mailto:<a href="mailto:christian.werner@rwth-aachen.de" target="_blank">christian.werner@rwth-aachen.de</a>&gt;&gt; wrote:<br>

<br>
    Hi!<br>
<br>
    I need a nice DistanceTransformation function. Danielsson is fine<br>
    but slooooow. Then I tried the SignedMaurerDistanceMapImageFilter<br>
    which is quite fast. Unfortunately the results are quite<br>
    different. It seems the DanielsonDistanceMapImageFilter yields<br>
    better results. What am I doing wrong?<br>
<br>
    I am passing no input parameter to the filters, I just put them in<br>
    the pipeline. Maybe I am missing important parameters? They are<br>
    both used the exactly same way:<br>
<br>
     ///// typedef typename itk::DanielssonDistanceMapImageFilter&lt;<br>
    ImageType, ImageType &gt; FilterType;<br>
     typedef typename itk::SignedMaurerDistanceMapImageFilter&lt;<br>
    ImageType, ImageType &gt; FilterType;<br>
     typename FilterType::Pointer filter = FilterType::New();<br>
     filter-&gt;SetInput( itkImporter-&gt;GetOutput() );<br>
<br>
    Any idea?<br>
<br>
<br>
    Best regards,<br>
    Christian<br>
<br>
    _____________________________________<br></div>
    Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<div class="im"><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.html" target="_blank">http://www.kitware.com/products/protraining.html</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>
<br>
<br></div>
------------------------------------------------------------------------<br>
<br>
</blockquote>
<br>
</blockquote></div><br>