<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello Sergio,<div><br></div><div>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.</div><div><br></div><div>I wrote the following little SimpleITK python script, which uses the latest ITK 4.2rc04:</div><div><br></div><div><div><div>import SimpleITK as sitk</div><div>import os</div><div>from timeit import Timer</div><div><br></div><div>repeat = 10</div><div><br></div><div>img = sitk.Image( [512,512,110], sitk.sitkUInt8 )</div><div>img[255,255,55 ] = 1</div><div><br></div><div>filter = sitk.SignedMaurerDistanceMapImageFilter()</div><div><br></div><div>print "Defaults:"</div><div>print filter</div><div><br></div><div>t = Timer( lambda: filter.Execute( img ) )</div><div><br></div><div>print "The average time it took to execute", filter.GetName(), "was", &nbsp;min(t.repeat( repeat=repeat,number=1 )), "seconds. "</div><div><br></div><div>filter.InsideIsPositiveOff()</div><div>filter.SquaredDistanceOff()</div><div>filter.UseImageSpacingOn();</div><div><br></div><div>t = Timer( lambda: filter.Execute( img ) )</div><div><br></div><div>print "The average time it took to execute", filter.GetName(), "was", &nbsp;min(t.repeat( repeat=repeat,number=1 )), "seconds. "</div><div><br></div><div>t = Timer( lambda: filter.Execute( ~img ) )</div><div><br></div><div>print "The average time it took to execute", filter.GetName(), "was", &nbsp;min(t.repeat( repeat=repeat,number=1 )), "seconds. "</div></div></div><div><br></div><div>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:</div><div><br></div><div><div>Defaults:</div><div>itk::simple::SignedMaurerDistanceMapImageFilter</div><div>&nbsp; InsideIsPositive: 0</div><div>&nbsp; SquaredDistance: 1</div><div>&nbsp; UseImageSpacing: 0</div><div><br></div><div>The average time it took to execute SignedMaurerDistanceMap was 2.05940294266 seconds.&nbsp;</div><div>The average time it took to execute SignedMaurerDistanceMap was 2.61217999458 seconds.&nbsp;</div><div>The average time it took to execute SignedMaurerDistanceMap was 2.7291328907 seconds.&nbsp;</div></div><div><br></div><div><br></div><div>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.</div><div><br></div><div>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:</div><div><br></div><div><div>The average time it took to execute SignedMaurerDistanceMap was 8.77108097076 seconds.&nbsp;</div><div>The average time it took to execute SignedMaurerDistanceMap was 9.40146708488 seconds.&nbsp;</div><div>The average time it took to execute SignedMaurerDistanceMap was 9.63690400124 seconds.&nbsp;</div></div><div><br></div><div>I tend to agree with Bill, there is something funny about how you compiled it.</div><div><br></div><div>Brad</div><div><br></div><div><br></div><div><br></div><div><div>On Jul 2, 2012, at 9:31 AM, Sergio Vera wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hello Bill,</div>I did... that was my first check... I've rechecked it.. It compiles against ITK built in Release Mode...<br><br><br>Best regards<div><br><div class="gmail_quote">On Mon, Jul 2, 2012 at 1:48 PM, Bill Lorensen <span dir="ltr">&lt;<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@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">Make sure your ITK is built with Release and not Debug.<br><br><div class="gmail_quote"><div><div class="h5">On Mon, Jul 2, 2012 at 5:55 AM, Sergio Vera <span dir="ltr">&lt;<a href="mailto:sergio.vera@alma3d.com" target="_blank">sergio.vera@alma3d.com</a>&gt;</span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; "><div><div class="h5"><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Hello itkusers</span><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">


<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I've having some performance issues related with the calculation of distance maps through ITK's SignedMaurerDistanceMapImageFilter.</div>


<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
My execution times were a bit high so I've setup &nbsp;the following test:</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">


a 512x512x110 binary image</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
Matlab's bwdist (uses Maurer method, but does not generates a signed map) is the fastest one.</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Matlab Code:</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><font face="courier new, monospace">tic, d1 = bwdist(i); toc</font></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">


<font face="courier new, monospace">Elapsed time is 2.415929 seconds.</font></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><div><font face="courier new, monospace">tic, d2 = bwdist(~i); toc</font></div>


<div><font face="courier new, monospace">Elapsed time is 2.509455 seconds.</font></div><div><br></div><div>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.</div>


<div><br></div><div>Now, I load the same image in Mevislab Using ITK filters and compute the signedMaurer distance with this pipeline:</div><div><br></div><div><span>&lt;image.png&gt;</span></div>


<div><br></div><div>Mevislab Reports execution times in the range of 6.4 to 7.2 seconds&nbsp;which&nbsp;is comparable to Matlab's 5 seconds</div><div><br></div><div>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)</div>


<div><br></div><div>C++ Code:</div><div><div><font face="courier new, monospace">itk::TimeProbe timer;</font></div><div><font face="courier new, monospace">timer.Start();</font></div><div><font face="courier new, monospace">typedef itk::SignedMaurerDistanceMapImageFilter&nbsp;&lt;seg::ITKImgLabelType, F1d3ITKImgType&gt; DistanceMapper;</font></div>


<div><font face="courier new, monospace">DistanceMapper::Pointer distanceMapper = DistanceMapper::New();</font></div><div><font face="courier new, monospace">distanceMapper-&gt;ReleaseDataFlagOn();</font></div><div><font face="courier new, monospace">distanceMapper-&gt;SetUseImageSpacing(true);</font></div>


<div><font face="courier new, monospace">distanceMapper-&gt;SetSquaredDistance(false);</font></div><div><font face="courier new, monospace">distanceMapper-&gt;SetInsideIsPositive(false);<span style="white-space:pre-wrap">        </span></font></div>


<div><font face="courier new, monospace">distanceMapper-&gt;SetInput(&amp;a_segmentedImgIn);</font></div><div><font face="courier new, monospace">distanceMapper-&gt;SetNumberOfThreads(2);</font></div><div><font face="courier new, monospace">distanceMapper-&gt;Update();</font></div>


<div><font face="courier new, monospace">timer.Stop();</font></div><div><font face="courier new, monospace">SpyITK::OutputTimeToComplete(std::cout, __FUNCTION__, timer);</font></div></div><div><br></div><div>The image is already readed.&nbsp;</div>


<div><br></div><div>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).</div>


<div><br></div><div>Perhaps is some flag that has to be used when compiling ITK? Any further tips on how to speed the distance map calculation?</div><div><br></div><div>I can provide the file to used to test the performance if needed.</div>


<div><br></div><div>Thanks in advance</div></div><span><font color="#888888"><div><br></div>-- <br>Sergio Vera<br><br>&nbsp;Alma IT Systems<br>&nbsp;C/ Vilana, 4B, 4º 1ª<br>&nbsp;08022 Barcelona<br>&nbsp;T. <a href="tel:%28%2B34%29%20932%20380%20592" value="+34932380592" target="_blank">(+34) 932 380 592</a><br>

&nbsp;<a href="http://www.alma3d.com/" target="_blank">www.alma3d.com</a><br>

</font></span><br></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>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Unpaid intern in BillsBasement at noware dot com<br><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Sergio Vera<br><br>&nbsp;Alma IT Systems<br>&nbsp;C/ Vilana, 4B, 4º 1ª<br>&nbsp;08022 Barcelona<br>&nbsp;T. (+34) 932 380 592<br>&nbsp;<a href="http://www.alma3d.com/">www.alma3d.com</a><br>

</div>
_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></body></html>