[Insight-users] Problems with Maurer Distance Transform

Luis Ibanez luis.ibanez at kitware.com
Sun Apr 25 17:08:19 EDT 2010


Hi Christian,

Thanks for letting us know that the code works for you.

You really need a RescaleIntensityFilter.

The CastImageFilter will not do the trick here.

The distance image (in pixel type double) has a
dynamic range equal to

                -7.28     to   79.209

If you just attempt to cast it to an unsigned char
image, the negative values will roll over and
they will become

  -7   ------>  249
  -6   ------>  250
  -5   ------>  251
  -4   ------>  252
  -3   ------>  253
  -2   ------>  254
  -1  ------->  255


Note also that in a general case you distances
could easily be larger than 255, and in such
cases the value will also roll over to the low
values, as in

     256 ----->  1
     257 ----->  2
     258 ----->  3
     259 ----->  4

...

another option that you may want to consider is the
ShiftScale image filter, with a

            scale of 1.0 and a
            shift of 0.0

This filter will truncate the values that outside the
range of the output image.

Note that you still need to use a "signed" type for
the output pixel type, and that most of the basic
image file formats such as TIFF, JPEG and PNG
do not support signed integers.

In short, you may want to keep using the MetaImage
file format and the original double pixel type.


      Regards,


             Luis


--------------------------------------------------------------------------
On Sun, Apr 25, 2010 at 2:01 PM, Christian Werner <
christian.werner at rwth-aachen.de> wrote:

> Thank you very much. That double datatype turned out to be the reason for
> all the trouble I had. Your code works perfectly.
>
> 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. "Funny" 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)
>
> Any idea?
>
>
>
> Luis Ibanez wrote:
>
>>
>> Hi Christian,
>>
>>
>> As described in the Insight Journal paper:
>>
>> "N-D Linear Time Exact Signed Euclidean Distance Transform"
>> Tustison N.J., Siqueira M., Gee J.C.
>> University of Pennsylvania
>> http://www.insight-journal.org/browse/publication/77
>> http://hdl.handle.net/1926/171
>>
>>
>> where the ITK implementation of the Maurer filter was
>> introduced,
>>
>>
>> The Maurer filter computes the exact euclidean distance
>> (down to numerical precision), while the Danielsson
>> distance filter only approximates the distance up to a
>> 1 pixel spacing values.
>>
>>
>> It is therefore, not surprising that you find differences
>> between the distance values reported by these two
>> filters....
>>
>> However, the output that you are reporting for the
>> Signed Maurer distance really looks plain wrong     :-(
>>
>>
>> It would seem that you have a problem in the
>> instantiation of the filter.
>>
>>
>> I just ran the Signed Maurer from a modified version
>> of the Test in
>>
>>        Insight/Testing/Code/BasicFilters
>>
>> and using your input image (BTW: Thanks a lot for
>> providing the input image and output images, that
>> makes things a lot easier)  and it works fine for me.
>>
>>
>> Please find attached to this email the source
>> code that I used, and the output that I get from
>> the rescaled distance.
>>
>> Note that the distance is produced as an image
>> of pixel type double, so the command line that
>> I used was:
>>
>>
>> MaurerDistance input_image.png distance.mha \
>> maurer_output_uchar.png
>>
>> The exact distances are stored in the distance.mha
>> file ( the MetaImage file format supports pixel type
>> "double"), while the .png image holds a rescaled
>> version of the distance, that is just intended for
>> visualization (that rescaled one is the one attached
>> to this email).
>>
>> I had to pass the .png file through GIMP in order
>> to compress it further as a jpg file, to be able to
>> attach it to this email. The mailing list restricts
>> email size to 40Kb.
>>
>> --
>>
>> Please note also the setting of the filter:
>>
>>  filter->SetSquaredDistance( false );
>>  filter->SetUseImageSpacing( false );
>>  filter->SetInsideIsPositive( false );
>>
>>
>> Please give it a try at this code and let us know
>> if you find any problem.
>>
>>
>>     Thanks
>>
>>
>>          Luis
>>
>>
>>
>> -----------------------------------------------------------------------------------
>> On Sun, Apr 25, 2010 at 11:58 AM, Christian Werner <
>> christian.werner at rwth-aachen.de <mailto:christian.werner at rwth-aachen.de>>
>> wrote:
>>
>>    Hi!
>>
>>    I need a nice DistanceTransformation function. Danielsson is fine
>>    but slooooow. Then I tried the SignedMaurerDistanceMapImageFilter
>>    which is quite fast. Unfortunately the results are quite
>>    different. It seems the DanielsonDistanceMapImageFilter yields
>>    better results. What am I doing wrong?
>>
>>    I am passing no input parameter to the filters, I just put them in
>>    the pipeline. Maybe I am missing important parameters? They are
>>    both used the exactly same way:
>>
>>     ///// typedef typename itk::DanielssonDistanceMapImageFilter<
>>    ImageType, ImageType > FilterType;
>>     typedef typename itk::SignedMaurerDistanceMapImageFilter<
>>    ImageType, ImageType > FilterType;
>>     typename FilterType::Pointer filter = FilterType::New();
>>     filter->SetInput( itkImporter->GetOutput() );
>>
>>    Any idea?
>>
>>
>>    Best regards,
>>    Christian
>>
>>    _____________________________________
>>    Powered by www.kitware.com <http://www.kitware.com>
>>
>>
>>    Visit other Kitware open-source projects at
>>    http://www.kitware.com/opensource/opensource.html
>>
>>    Kitware offers ITK Training Courses, for more information visit:
>>    http://www.kitware.com/products/protraining.html
>>
>>    Please keep messages on-topic and check the ITK FAQ at:
>>    http://www.itk.org/Wiki/ITK_FAQ
>>
>>    Follow this link to subscribe/unsubscribe:
>>    http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100425/6207212d/attachment-0001.htm>


More information about the Insight-users mailing list