Hi Bradley!<div><br></div><div>Indeed the snippet of code used nonsense images (I tried to remove the conversion from unsigned char to float from the equation).</div><div>I've tested ITK 4.1 with a small improvement from 13 to 11 seconds.</div>
<div>But your pacth improved the results to merely 6 seconds of time, bringing the times 50% down.</div><div><br></div><div>Many thanks</div><div>
<br><div class="gmail_quote">On Tue, Jul 3, 2012 at 5:31 AM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>Hello Sergio,</div><div><br></div><div>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.</div>
<div><br></div><div>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:</div><div><br></div><a href="http://review.source.kitware.com/#/c/6367/" target="_blank">http://review.source.kitware.com/#/c/6367/</a><div>
<br></div><div>I haven't tried running your code yet. The performance difference still seems very off to me.</div><div><br></div><div>Brad</div><div><div><div><br><div><br><div><div>On Jul 2, 2012, at 12:15 PM, Sergio Vera wrote:</div>
<br><blockquote type="cite">Hi
<span style="text-align:left;white-space:nowrap;font-family:arial,sans-serif">Dženan and Bradley,</span><div><div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap"><br>
</span></font></div><div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap">I use Control+F5 normally. and it's a Professional version of Visual Studio 9 (2008)</span></font></div>
<div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap"><br></span></font></div><div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap">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. </span></font></div>
<div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap">By the way switching to ITK 4.0 did not improve my numbers :(</span></font></div><div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap"><div>
<br></div><div>cmake_minimum_required(VERSION 2.6)</div><div>project(dmap)</div><div>find_package(ITK REQUIRED)</div><div>include(${ITK_USE_FILE})</div><div>add_executable(dmap main.cxx)</div><div>target_link_libraries(dmap ${ITK_LIBRARIES})</div>
</span></font></div><div style="text-align:left"><font face="arial, sans-serif"><span style="white-space:nowrap"><br></span></font></div><table cellpadding="0" style="border-collapse:collapse;color:rgb(34,34,34);width:202px;overflow:hidden;font-family:arial,sans-serif;table-layout:fixed;outline:none">
<tbody><tr><td style="margin:0px;font-family:arial,sans-serif;overflow:hidden;text-align:left;text-overflow:ellipsis;white-space:nowrap;vertical-align:top"><span style="background-color:transparent">#include <itkTimeProbe.h></span></td>
</tr></tbody></table><div>#include <itkImage.h></div><div>#include <itkImageFileReader.h></div><div>#include <itkSignedMaurerDistanceMapImageFilter.h></div><div><br></div><div>int main(int argc, char *argv[])</div>
<div>{</div><div><span style="white-space:pre-wrap">        </span>typedef itk::Image<unsigned char,3> ITKImg;</div><div><span style="white-space:pre-wrap">        </span>typedef itk::ImageFileReader<ITKImg> Reader;</div>
<div><span style="white-space:pre-wrap">        </span>Reader::Pointer reader = Reader::New();</div><div><span style="white-space:pre-wrap">        </span>reader->SetFileName("C:/Users/sergio.vera/Documents/MATLAB/images/CTAbdomenThr1800.mha");</div>
<div><span style="white-space:pre-wrap">        </span>reader->Update();</div><div><span style="white-space:pre-wrap">        </span>std::cout << "Image readed!\n ";</div><div><span style="white-space:pre-wrap">        </span>itk::TimeProbe timer;</div>
<div><span style="white-space:pre-wrap">        </span>timer.Start();</div><div><span style="white-space:pre-wrap">        </span>typedef itk::SignedMaurerDistanceMapImageFilter <ITKImg, ITKImg> DistanceMapper;</div>
<div><span style="white-space:pre-wrap">        </span>DistanceMapper::Pointer distanceMapper = DistanceMapper::New();</div><div><span style="white-space:pre-wrap">        </span>distanceMapper->SetUseImageSpacing(true);</div>
<div><span style="white-space:pre-wrap">        </span>distanceMapper->SetSquaredDistance(false);</div><div><span style="white-space:pre-wrap">        </span>distanceMapper->SetInsideIsPositive(false);<span style="white-space:pre-wrap">        </span></div>
<div><span style="white-space:pre-wrap">        </span>distanceMapper->SetInput(reader->GetOutput());</div><div><span style="white-space:pre-wrap">        </span>distanceMapper->SetNumberOfThreads(2);</div>
<div><span style="white-space:pre-wrap">        </span>distanceMapper->Update();</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>timer.Stop();</div>
<div><span style="white-space:pre-wrap">        </span>std::cout << "Time Spent: " << timer.GetMeanTime() << "\n";</div><div> return EXIT_SUCCESS;</div><div>}</div><br><br>
<div class="gmail_quote">On Mon, Jul 2, 2012 at 6:02 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br><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">
<div style="word-wrap:break-word">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.<div><br></div>
<div>Brad</div><div><br><div><div><div><div><div>On Jul 2, 2012, at 11:38 AM, Sergio Vera wrote:</div><br><blockquote type="cite">Hello Bradley<div><br></div><div>Thanks for your script</div><div><br></div><div>
I've tried your script and the timings are coherent with yours (although my desktop is slower than your laptop :) )</div>
<div><br></div><div><div>The average time it took to execute SignedMaurerDistanceMap was 5.3353600223 seconds. </div><div>The average time it took to execute SignedMaurerDistanceMap was 6.62535580948 seconds. </div><div>
The average time it took to execute SignedMaurerDistanceMap was 6.90300935124 seconds. </div>
<div><br></div><div>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....</div>
<div><br></div><div><div>The average time it took to execute SignedMaurerDistanceMap was 8.87152283895 seconds. </div><div>The average time it took to execute SignedMaurerDistanceMap was 9.38857726434 seconds. </div><div>
The average time it took to execute SignedMaurerDistanceMap was 9.54250972999 seconds. </div></div><div><br></div><div>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..</div>
<div><br></div><div>Thanks</div>
<br><div class="gmail_quote">On Mon, Jul 2, 2012 at 4:07 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br>
<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"><div><div>Hello Sergio,<br>
<br>
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.<br>
<br>
I wrote the following little SimpleITK python script, which uses the latest ITK 4.2rc04:<br>
<br>
import SimpleITK as sitk<br>
import os<br>
from timeit import Timer<br>
<br>
repeat = 10<br>
<br>
img = sitk.Image( [512,512,110], sitk.sitkUInt8 )<br>
img[255,255,55 ] = 1<br>
<br>
filter = sitk.SignedMaurerDistanceMapImageFilter()<br>
<br>
print "Defaults:"<br>
print filter<br>
<br>
t = Timer( lambda: filter.Execute( img ) )<br>
<br>
print "The average time it took to execute", filter.GetName(), "was", min(t.repeat( repeat=repeat,number=1 )), "seconds. "<br>
<br>
filter.InsideIsPositiveOff()<br>
filter.SquaredDistanceOff()<br>
filter.UseImageSpacingOn();<br>
<br>
t = Timer( lambda: filter.Execute( img ) )<br>
<br>
print "The average time it took to execute", filter.GetName(), "was", min(t.repeat( repeat=repeat,number=1 )), "seconds. "<br>
<br>
t = Timer( lambda: filter.Execute( ~img ) )<br>
<br>
print "The average time it took to execute", filter.GetName(), "was", min(t.repeat( repeat=repeat,number=1 )), "seconds. "<br>
<br>
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:<br>
<br>
Defaults:<br>
itk::simple::SignedMaurerDistanceMapImageFilter<br>
InsideIsPositive: 0<br>
SquaredDistance: 1<br>
UseImageSpacing: 0<br>
<br>
The average time it took to execute SignedMaurerDistanceMap was 2.05940294266 seconds.<br>
The average time it took to execute SignedMaurerDistanceMap was 2.61217999458 seconds.<br>
The average time it took to execute SignedMaurerDistanceMap was 2.7291328907 seconds.<br>
<br>
<br>
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.<br>
<br>
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:<br>
<br>
The average time it took to execute SignedMaurerDistanceMap was 8.77108097076 seconds.<br>
The average time it took to execute SignedMaurerDistanceMap was 9.40146708488 seconds.<br>
The average time it took to execute SignedMaurerDistanceMap was 9.63690400124 seconds.<br>
<br>
I tend to agree with Bill, there is something funny about how you compiled it.<br>
<br>
Brad<br>
<br>
</div></div><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>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. <a href="tel:%28%2B34%29%20932%20380%20592" value="+34932380592" target="_blank">(+34) 932 380 592</a><br>
<a href="http://www.alma3d.com/" target="_blank">www.alma3d.com</a><br>
</div>
</blockquote></div><br></div></div><div>
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:12px;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:12px;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font face="Helvetica" size="3" style="font:normal normal normal 12px/normal Helvetica">========================================================</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font face="Helvetica" size="3" style="font:normal normal normal 12px/normal Helvetica">Bradley Lowekamp<span> </span><span> </span></font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font face="Helvetica" size="3" style="font:normal normal normal 12px/normal Helvetica">Medical Science and Computing for</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica" size="3" style="font:normal normal normal 12px/normal Helvetica">Office of High Performance Computing and Communications</font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica" size="3" style="font:normal normal normal 12px/normal Helvetica">National Library of Medicine<span> </span></font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font face="Helvetica" size="3" style="font:normal normal normal 12px/normal Helvetica"><a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a></font></div><br></span></div></span></span><br>
</div>
<br></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. <a href="tel:%28%2B34%29%20932%20380%20592" value="+34932380592" target="_blank">(+34) 932 380 592</a><br>
<a href="http://www.alma3d.com/" target="_blank">www.alma3d.com</a><br>
</div>
</blockquote></div><br></div></div></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. <a href="tel:%28%2B34%29%20932%20380%20592" value="+34932380592" target="_blank">(+34) 932 380 592</a><br>
<a href="http://www.alma3d.com" target="_blank">www.alma3d.com</a><br>
</div>