<div dir="ltr"><br>Hi Sara,<br><br>Thanks for your detailed question regarding Watersheds.<br><br><br>Please take a look at the attached code.<br><br>It process the image "Patient01" from <br><br> <span style="color: rgb(163, 21, 21);"><a href="http://public.kitware.com/pub/itk/Data/LiverTumor/" rel="nofollow" target="_blank"><font color="#800080">http://public.kitware.com/pub/itk/Data/LiverTumor/</font></a>.</span><br>
<br>in a time of<br><br> 4 minutes 38 seconds.<br><br>This was profiled in an QuadCore Intel Xeon 2.66 Ghz. (with 16Gb RAM).<br>(although the process uses only one of the cores)<br><br>Note that the process peaks 1Gb of memory allocation when it is running.<br>
<br>Depending on the configuration of your system, it may be that the program<br>started swapping memory at some point.<br><br>Please give a try at the attached code and let us know what you find.<br><br><br> Regards,<br>
<br><br> Luis<br><br><br>-----------------------------------------------------------------------------------------------------------------------------------<br><div class="gmail_quote">On Fri, Aug 22, 2008 at 11:19 AM, sara meghellati <span dir="ltr"><<a href="mailto:sara_meghellati@yahoo.fr">sara_meghellati@yahoo.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
I'm sending again my questions as nobody have answered me. <br><br>--- En date de : <b>Ven 22.8.08, sara meghellati <i><<a href="mailto:sara_meghellati@yahoo.fr" target="_blank">sara_meghellati@yahoo.fr</a>></i></b> a écrit :<br>
<blockquote style="border-left: 2px solid rgb(16, 16, 255); padding-left: 5px; margin-left: 5px;">De: sara meghellati <<a href="mailto:sara_meghellati@yahoo.fr" target="_blank">sara_meghellati@yahoo.fr</a>><br>Objet: [Insight-users] Please help:problem with wathershed segmentation applied to 3D grayscale Image<br>
À: "insight itk" <<a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>><br>Date: Vendredi 22 Août 2008, 13h48<br><br>
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td valign="top"><pre><span>Dear itk experts,</span></pre><pre><span>I'm segmenting a volume (3D grayscale image) using watershed method inspired from the WatershedSegmentation1 </span></pre><pre><span>(2D </span><span>RGB</span><span> image as input)example provided within itk.</span></pre>
<pre><span>My code is well working for 2D grayscale images but when I change </span></pre><pre><span>the dimension to 3, the code
still running as it get stuck in a </span></pre><pre><span>loop!! I wait for more than 18min but no results!! Is it normal </span></pre><pre><span>that this kind of segmentation takes age to give the result in 3d </span></pre>
<pre><span>image or there is some thing wrong with my code? Please could you help me on that? Also, how can I follow the progress of the code?</span></pre><pre><span>I pass my code bellow. In this example I used the 3D data provided</span></pre>
<pre><span>in</span><span style="color: rgb(163, 21, 21);"> <a href="http://public.kitware.com/pub/itk/Data/LiverTumor/" rel="nofollow" target="_blank"><font color="#800080">http://public.kitware.com/pub/itk/Data/LiverTumor/</font></a>.</span></pre>
<pre><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);"><iostream></span></span></pre>
<p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkImage.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkGradientAnisotropicDiffusionImageFilter.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkGradientMagnitudeImageFilter.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkWatershedImageFilter.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkImageFileReader.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkImageFileWriter.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkVectorCastImageFilter.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkUnaryFunctorImageFilter.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkScalarToRGBPixelFunctor.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: rgb(163, 21, 21);"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkVTKImageExport.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"itkVTKImageImport.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: rgb(163, 21, 21);"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkImageData.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkImageImport.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkImageExport.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkImageActor.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkRenderer.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkRenderWindow.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkRenderWindowInteractor.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkInteractorStyleTrackballCamera.h"</span> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">#include</span><span style="font-size: 10pt;"> <span style="color: rgb(163, 21, 21);">"vtkImageShiftScale.h"</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: rgb(163, 21, 21);"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: green;">// This function will connect the given itk::VTKImageExport filter to the given vtkImageImport filter.</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">template</span><span style="font-size: 10pt;"> <<span style="color: blue;">typename</span> ITK_Exporter, <span style="color: blue;">typename</span> VTK_Importer></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">void</span><span style="font-size: 10pt;"> ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;">{</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetSpacingCallback(exporter->GetSpacingCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetOriginCallback(exporter->GetOriginCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetDataExtentCallback(exporter->GetDataExtentCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>importer->SetCallbackUserData(exporter->GetCallbackUserData());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;">}</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">int</span><span style="font-size: 10pt;"> main( )</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;">{<span> </span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::Image<<span style="color: blue;">float</span>, 3><span> </span>ImageType; <span style="color: green;"></span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::Image<<span style="color: blue;">unsigned</span> <span style="color: blue;">long</span>, 3><span> </span>LabeledImageType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::Image<<span style="color: blue;">float</span>, 3><span> </span>ScalarImageType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: green;">// for visualization purposes</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::RGBPixel<<span style="color: blue;">unsigned</span> <span style="color: blue;">char</span>><span> </span>RGBPixelType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::Image<RGBPixelType, 3><span> </span>RGBImageType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::ImageFileReader<ImageType> FileReaderType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::GradientAnisotropicDiffusionImageFilter<ImageType,<span> </span>ImageType><span> </span>DiffusionFilterType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::GradientMagnitudeImageFilter<ImageType,ImageType><span> </span>GradientMagnitudeFilterType; </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::WatershedImageFilter<ScalarImageType> WatershedFilterType; <span style="color: green;"></span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::ImageFileWriter<RGBImageType> FileWriterType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>FileReaderType::Pointer reader = FileReaderType::New</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>reader->SetFileName( <span style="color: rgb(163, 21, 21);">"c:/images/3DImages/Patient01.mhd"</span><span> </span>);</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: green;">//reader->SetFileName("c:/Images/BrainProtonDensitySlice.png");</span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: green;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>diffusion->SetNumberOfIterations( atoi(<span style="color: rgb(163, 21, 21);">"10"</span>) );</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>diffusion->SetConductanceParameter( atof(<span style="color: rgb(163, 21, 21);">"2.0"</span>) );</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>diffusion->SetTimeStep(0.0625);</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: green;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>GradientMagnitudeFilterType::Pointer gradient = GradientMagnitudeFilterType::New();</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>WatershedFilterType::Pointer watershed = WatershedFilterType::New();</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>watershed->SetLevel( atof(<span style="color: rgb(163, 21, 21);">"0.15"</span>) );<span> </span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>watershed->SetThreshold( atof(<span style="color: rgb(163, 21, 21);">"0.001"</span>) );<span> </span><span style="color: green;"></span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::Functor::ScalarToRGBPixelFunctor<<span style="color: blue;">unsigned</span> <span style="color: blue;">long</span>><span> </span>ColorMapFunctorType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">typedef</span> itk::UnaryFunctorImageFilter<LabeledImageType,<span> </span>RGBImageType, ColorMapFunctorType> ColorMapFilterType;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>FileWriterType::Pointer writer = FileWriterType::New();</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>writer->SetFileName(<span style="color: rgb(163, 21, 21);">"c:/Images/WatershedSegImg.mhd"</span>);</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>diffusion->SetInput(reader->GetOutput());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>gradient->SetInput(diffusion->GetOutput());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>watershed->SetInput(gradient->GetOutput());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>colormapper->SetInput(watershed->GetOutput());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>writer->SetInput(colormapper->GetOutput());</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>writer->Update();</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: blue;">try</span><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>{</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>writer->Update();<span> </span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span> </span>}</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">catch</span> (itk::ExceptionObject &e)</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>{</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>std::cerr << e << std::endl;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span>}</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span></span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"><span> </span><span style="color: blue;">return</span> 0;</span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;"> </span>
</p><p style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt;">}</span></p><pre><span></span></pre><pre><span>Thanks</span></pre><pre>Sara <span></span></pre></td></tr></tbody></table><br>
<hr size="1">
Envoyé avec <a href="http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html" rel="nofollow" target="_blank">Yahoo! Mail</a>.<br>Une boite mail plus intelligente. </div>
<pre>_______________________________________________
Insight-users mailing list
<a href="mailto:Insight-users@itk.org" target="_blank">Insight-users@itk.org</a>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a>
</pre></blockquote></td></tr></tbody></table><div class="WgoR0d"><br>
<hr size="1">
Envoyé avec <a href="http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html" target="_blank">Yahoo! Mail</a>.<br>Une boite mail plus intelligente. </div>
<br>_______________________________________________<br>
Insight-users mailing list<br>
<a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><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><br></div>