[Insight-users] [offlist] SignedMaurerDistanceMapImageFilter performance

Sergio Vera sergio.vera at alma3d.com
Tue Jul 3 06:41:52 EDT 2012


Hi Bradley!

Indeed the snippet of code used nonsense images (I tried to remove the
conversion from unsigned char to float from the equation).
I've tested ITK 4.1 with a small improvement from 13 to 11 seconds.
But your pacth improved the results to merely 6 seconds of time, bringing
the times 50% down.

Many thanks

On Tue, Jul 3, 2012 at 5:31 AM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:

> Hello Sergio,
>
> I did also notice that you have a different output pixel type than I.
> Simple ITK was using float. As you are using output pixel type uchar, but
> with using image spacing, I am not sure how much sense that combination
> makes. Additionally you have signed output into uchar. This may be part for
> the problem. I tried changing the output pixel type in simpleITK to the
> same as the input, and I got similar to slightly faster results.
>
> Looking at the code, I did see a multi-threadhing issue, I have made a
> patch for it, that is still a work in progress:
>
> http://review.source.kitware.com/#/c/6367/
>
> I haven't tried running your code yet. The performance difference still
> seems very off to me.
>
> Brad
>
>
> On Jul 2, 2012, at 12:15 PM, Sergio Vera wrote:
>
> Hi  Dženan and Bradley,
>
> I use Control+F5 normally. and it's a Professional version of Visual
> Studio 9 (2008)
>
> I've made a minimum test scenario to remove any possible interferences
> from other libraries/dependencies. This one only links against ITK, and
> still times are arrount 13-14 segs.
> By the way switching to ITK 4.0 did not improve my numbers :(
>
> cmake_minimum_required(VERSION 2.6)
> project(dmap)
> find_package(ITK REQUIRED)
> include(${ITK_USE_FILE})
> add_executable(dmap main.cxx)
> target_link_libraries(dmap  ${ITK_LIBRARIES})
>
> #include <itkTimeProbe.h>
> #include <itkImage.h>
> #include <itkImageFileReader.h>
> #include <itkSignedMaurerDistanceMapImageFilter.h>
>
> int main(int argc, char *argv[])
> {
> typedef itk::Image<unsigned char,3> ITKImg;
> typedef itk::ImageFileReader<ITKImg> Reader;
>  Reader::Pointer reader = Reader::New();
>
> reader->SetFileName("C:/Users/sergio.vera/Documents/MATLAB/images/CTAbdomenThr1800.mha");
>  reader->Update();
> std::cout << "Image readed!\n ";
> itk::TimeProbe timer;
>  timer.Start();
> typedef itk::SignedMaurerDistanceMapImageFilter <ITKImg, ITKImg>
> DistanceMapper;
>  DistanceMapper::Pointer distanceMapper = DistanceMapper::New();
> distanceMapper->SetUseImageSpacing(true);
>  distanceMapper->SetSquaredDistance(false);
> distanceMapper->SetInsideIsPositive(false);
>  distanceMapper->SetInput(reader->GetOutput());
> distanceMapper->SetNumberOfThreads(2);
>  distanceMapper->Update();
>  timer.Stop();
>  std::cout << "Time Spent: " << timer.GetMeanTime() << "\n";
>   return EXIT_SUCCESS;
> }
>
>
> On Mon, Jul 2, 2012 at 6:02 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:
>
>> Would you by any chance be using an express Visual Studio version? Those
>> compiler are missing a fair amount of optimization. I have not compared the
>> difference myself though.
>>
>> Brad
>>
>> On Jul 2, 2012, at 11:38 AM, Sergio Vera wrote:
>>
>> Hello Bradley
>>
>> Thanks for your script
>>
>> I've tried your script and the timings are coherent with yours (although
>> my desktop is slower than your laptop :) )
>>
>> The average time it took to execute SignedMaurerDistanceMap was
>> 5.3353600223 seconds.
>> The average time it took to execute SignedMaurerDistanceMap was
>> 6.62535580948 seconds.
>> The average time it took to execute SignedMaurerDistanceMap was
>> 6.90300935124 seconds.
>>
>> I've modified it to read my image (it's only 300k but it seems too big
>> for the list) and the results are definitely lower than 13 seconds, closer
>> to the 7 seconds from Mevislab's ITK....
>>
>> The average time it took to execute SignedMaurerDistanceMap was
>> 8.87152283895 seconds.
>> The average time it took to execute SignedMaurerDistanceMap was
>> 9.38857726434 seconds.
>> The average time it took to execute SignedMaurerDistanceMap was
>> 9.54250972999 seconds.
>>
>> Indeed it is strange that my code runs slower :( My executable being
>> compiled in release mode, compiler flags are /02 and Visual studio is
>> clearly put in release. Also, when I launch the debug version the distance
>> map time is 114 seconds. However I'm not sure why it tools so long to
>> compute the distance map..
>>
>> Thanks
>>
>> On Mon, Jul 2, 2012 at 4:07 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:
>>
>>> 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
>>>
>>> _____________________________________
>>> 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
>>>
>>
>>
>>
>> --
>> Sergio Vera
>>
>>  Alma IT Systems
>>  C/ Vilana, 4B, 4º 1ª
>>  08022 Barcelona
>>  T. (+34) 932 380 592
>>  www.alma3d.com
>>
>>
>>  ========================================================
>> Bradley Lowekamp
>> Medical Science and Computing for
>> Office of High Performance Computing and Communications
>> National Library of Medicine
>>  blowekamp at mail.nih.gov
>>
>>
>>
>>
>
>
> --
> Sergio Vera
>
>  Alma IT Systems
>  C/ Vilana, 4B, 4º 1ª
>  08022 Barcelona
>  T. (+34) 932 380 592
>  www.alma3d.com
>
>
>


-- 
Sergio Vera

 Alma IT Systems
 C/ Vilana, 4B, 4º 1ª
 08022 Barcelona
 T. (+34) 932 380 592
 www.alma3d.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120703/a13b997b/attachment.htm>


More information about the Insight-users mailing list