[Insight-users] SignedMaurerDistanceMapImageFilter performance

Bradley Lowekamp blowekamp at mail.nih.gov
Mon Jul 2 10:06:07 EDT 2012


Hello Sergio,

But are you compiling your program also in release mode? The filter is not part of the ITK code in the library, because it is a templated filter, it will be compiled in your application, so that is where it matters if you are in Release or debug mode.

I wrote the following little SimpleITK python script, which uses the latest ITK 4.2rc04:

import SimpleITK as sitk
import os
from timeit import Timer

repeat = 10

img = sitk.Image( [512,512,110], sitk.sitkUInt8 )
img[255,255,55 ] = 1

filter = sitk.SignedMaurerDistanceMapImageFilter()

print "Defaults:"
print filter

t = Timer( lambda: filter.Execute( img ) )

print "The average time it took to execute", filter.GetName(), "was",  min(t.repeat( repeat=repeat,number=1 )), "seconds. "

filter.InsideIsPositiveOff()
filter.SquaredDistanceOff()
filter.UseImageSpacingOn();

t = Timer( lambda: filter.Execute( img ) )

print "The average time it took to execute", filter.GetName(), "was",  min(t.repeat( repeat=repeat,number=1 )), "seconds. "

t = Timer( lambda: filter.Execute( ~img ) )

print "The average time it took to execute", filter.GetName(), "was",  min(t.repeat( repeat=repeat,number=1 )), "seconds. "

Your large image didn't come attached, so I just created a trivial on to run performance. This is my results in my i7 laptop:

Defaults:
itk::simple::SignedMaurerDistanceMapImageFilter
  InsideIsPositive: 0
  SquaredDistance: 1
  UseImageSpacing: 0

The average time it took to execute SignedMaurerDistanceMap was 2.05940294266 seconds. 
The average time it took to execute SignedMaurerDistanceMap was 2.61217999458 seconds. 
The average time it took to execute SignedMaurerDistanceMap was 2.7291328907 seconds. 


As I was running this multiple times, I appear to be getting a variation of ~.5 seconds due to what I am assuming is the temperature of my CPU, and intel's TuboBoost.

Additionally, it's not clear which timings are using only one thread and which are using more. So I also ran the test with only one thread:

The average time it took to execute SignedMaurerDistanceMap was 8.77108097076 seconds. 
The average time it took to execute SignedMaurerDistanceMap was 9.40146708488 seconds. 
The average time it took to execute SignedMaurerDistanceMap was 9.63690400124 seconds. 

I tend to agree with Bill, there is something funny about how you compiled it.

Brad



On Jul 2, 2012, at 9:31 AM, Sergio Vera wrote:

> Hello Bill,
> I did... that was my first check... I've rechecked it.. It compiles against ITK built in Release Mode...
> 
> 
> Best regards
> 
> On Mon, Jul 2, 2012 at 1:48 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> Make sure your ITK is built with Release and not Debug.
> 
> On Mon, Jul 2, 2012 at 5:55 AM, Sergio Vera <sergio.vera at alma3d.com> wrote:
> Hello itkusers
> 
> I've having some performance issues related with the calculation of distance maps through ITK's SignedMaurerDistanceMapImageFilter.
> 
> My execution times were a bit high so I've setup  the following test:
> 
> a 512x512x110 binary image
> 
> Matlab's bwdist (uses Maurer method, but does not generates a signed map) is the fastest one.
> 
> Matlab Code:
> 
> tic, d1 = bwdist(i); toc
> Elapsed time is 2.415929 seconds.
> tic, d2 = bwdist(~i); toc
> Elapsed time is 2.509455 seconds.
> 
> The dmap is computed for the image and the negated image, to compensate that bwdist does only "half" of the distance map. Total time is about 5 seconds.
> 
> Now, I load the same image in Mevislab Using ITK filters and compute the signedMaurer distance with this pipeline:
> 
> <image.png>
> 
> Mevislab Reports execution times in the range of 6.4 to 7.2 seconds which is comparable to Matlab's 5 seconds
> 
> However, my code runs in 15 seconds, (13 if I enable 2 threads into SignedMaurer). I've checked that I use Release version of ITK (3.20)
> 
> C++ Code:
> itk::TimeProbe timer;
> timer.Start();
> typedef itk::SignedMaurerDistanceMapImageFilter <seg::ITKImgLabelType, F1d3ITKImgType> DistanceMapper;
> DistanceMapper::Pointer distanceMapper = DistanceMapper::New();
> distanceMapper->ReleaseDataFlagOn();
> distanceMapper->SetUseImageSpacing(true);
> distanceMapper->SetSquaredDistance(false);
> distanceMapper->SetInsideIsPositive(false);	
> distanceMapper->SetInput(&a_segmentedImgIn);
> distanceMapper->SetNumberOfThreads(2);
> distanceMapper->Update();
> timer.Stop();
> SpyITK::OutputTimeToComplete(std::cout, __FUNCTION__, timer);
> 
> The image is already readed. 
> 
> I've included the image that I use to benchmark the filter... It is strange that I'm having such a different result between Mevislab and my Own ITK code. The setup of the filter is similar (the only activated flag is the UseImageSpacingFlag).
> 
> Perhaps is some flag that has to be used when compiling ITK? Any further tips on how to speed the distance map calculation?
> 
> I can provide the file to used to test the performance if needed.
> 
> Thanks in advance
> 
> -- 
> Sergio Vera
> 
>  Alma IT Systems
>  C/ Vilana, 4B, 4º 1ª
>  08022 Barcelona
>  T. (+34) 932 380 592
>  www.alma3d.com
> 
> _____________________________________
> Powered by 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.php
> 
> 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
> 
> 
> 
> 
> -- 
> Unpaid intern in BillsBasement at noware dot com
> 
> 
> 
> 
> -- 
> Sergio Vera
> 
>  Alma IT Systems
>  C/ Vilana, 4B, 4º 1ª
>  08022 Barcelona
>  T. (+34) 932 380 592
>  www.alma3d.com
> _____________________________________
> Powered by 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.php
> 
> 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/20120702/c8af787b/attachment-0001.htm>


More information about the Insight-users mailing list