[Insight-users] Watersheds performace in Debug mode
wassim_belhadj at topnet.tn
wassim_belhadj at topnet.tn
Wed Aug 27 02:40:18 EDT 2008
Hi
I tried the wathershed segmentation example applied to "Patient01" from
http://public.kitware.com/pub/itk/Data/LiverTumor/.
The code still running as it get stuck in a loop. I used 0.001 for
threshold and 0.1 for the level parameter.
My CPU is Pentium 4, 3.00Ghz and 1Gb of Ram
How have you been able to Operate the example ?
I need Your Help Please.
This is the source code :
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
#include "itkWatershedImageFilter.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkScalarToRGBPixelFunctor.h"
#include "itkUnaryFunctorImageFilter.h"
#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"
int main( int argc, char *argv[] )
{
if( argc < 5 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage lowerThreshold
outputScaleLevel" << std::endl;
return 1;
}
typedef float InternalPixelType;
typedef itk::RGBPixel<unsigned char> RGBPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
typedef itk::Image< RGBPixelType, Dimension > RGBImageType;
//
// We instantiate reader and writer types
//
typedef itk::ImageFileReader< InternalImageType > ReaderType;
typedef itk::ImageFileWriter< RGBImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( argv[1] );
writer->SetFileName( argv[2] );
//
// Instantiate the GradientMagnitude image filter
//
typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
InternalImageType,
InternalImageType
>
GradientMagnitudeFilterType;
GradientMagnitudeFilterType::Pointer gradienMagnitudeFilter =
GradientMagnitudeFilterType::New();
gradienMagnitudeFilter->SetInput( reader->GetOutput() );
gradienMagnitudeFilter->SetSigma( 1.0 );
//
// Instantiate the Watershed filter
//
typedef itk::WatershedImageFilter<
InternalImageType
> WatershedFilterType;
WatershedFilterType::Pointer watershedFilter =
WatershedFilterType::New();
watershedFilter->SetInput( gradienMagnitudeFilter->GetOutput() );
watershedFilter->SetThreshold( atof( argv[3] ) );
watershedFilter->SetLevel( atof( argv[4] ) );
//
// Instantiate the filter that will encode the label image
// into a color image (random color attribution).
//
typedef itk::Functor::ScalarToRGBPixelFunctor<
unsigned long
> ColorMapFunctorType;
typedef WatershedFilterType::OutputImageType LabeledImageType;
typedef itk::UnaryFunctorImageFilter<
LabeledImageType,
RGBImageType,
ColorMapFunctorType
> ColorMapFilterType;
ColorMapFilterType::Pointer colorMapFilter = ColorMapFilterType::New();
colorMapFilter->SetInput( watershedFilter->GetOutput() );
writer->SetInput( colorMapFilter->GetOutput() );
try
{
writer->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
return 0;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
On Tue, 26 Aug 2008 11:04:50 -0400, Luis Ibanez <luis.ibanez at kitware.com>
wrote:
>
> Sara,
>
> When reporting performance issues,
> please build first under *Release* mode.
>
> As Dan described, you can easily find differences of one order of
> magnitude between the performance on Debug and Release modes.
>
> This is mainly due to the heavy use we made of C++ templates in ITK.
>
>
> Regards,
>
>
> Luis
>
>
> -------------------------
> sara meghellati wrote:
>> No, it was in debug mode. I will give a try at release mode.
>> Thanks Dan.
>> Cheers
>> Sara
>>
>> --- En date de : *Mar 26.8.08, Dan Mueller /<dan.muel at gmail.com>/* a
> écrit :
>>
>> De: Dan Mueller <dan.muel at gmail.com>
>> Objet: Re: [Insight-users] nobody could answer me ? Fw : Please
>> help:problem with wathershed segmentation applied to 3D grayscale
> Image
>> À: sara_meghellati at yahoo.fr
>> Cc: "Luis Ibanez" <luis.ibanez at kitware.com>, "insight itk"
>> <insight-users at itk.org>
>> Date: Mardi 26 Août 2008, 10h42
>>
>> Hi Sara,
>>
>> Did you compile the code in Release mode? Compiling in Release mode
>> (as opposed to Debug mode) significantly improves performance...
>>
>> 2008/8/26 sara meghellati <sara_meghellati at yahoo.fr>:
>>> Dear Luis,
>>> I would like to thank you and all the other itk members who have
> replied
>> me
>>> regarding my question.
>>> I have gave a try with your code. my CPU is Intel core 2, 2.41 Ghz and
> 2
>> Gb
>>> of Ram. it takes nearly 34 minutes. So I have tried my code, its
> working
>> and
>>> it takes also nearly 34 minutes. I used 0.001 for threshold and 0.1 for
>> the
>>> level parameter.
>>> Sara
>>> Best regards
>>>
>>> --- En date de : Ven 22.8.08, Luis Ibanez <luis.ibanez at kitware.com>
>> a
>>> écrit :
>>>
>>> De: Luis Ibanez <luis.ibanez at kitware.com>
>>> Objet: Re: [Insight-users] nobody could answer me ? Fw : Please
>> help:problem
>>> with wathershed segmentation applied to 3D grayscale Image
>>> À: sara_meghellati at yahoo.fr
>>> Cc: "insight itk" <insight-users at itk.org>
>>> Date: Vendredi 22 Août 2008, 18h59
>>>
>>>
>>> Hi Sara,
>>>
>>> Thanks for your detailed question regarding Watersheds.
>>>
>>>
>>> Please take a look at the attached code.
>>>
>>> It process the image "Patient01" from
>>>
>>> http://public.kitware.com/pub/itk/Data/LiverTumor/.
>>>
>>> in a time of
>>>
>>> 4 minutes 38 seconds.
>>>
>>> This was profiled in an QuadCore Intel Xeon 2.66 Ghz. (with 16Gb RAM).
>>> (although the process uses only one of the cores)
>>>
>>> Note that the process peaks 1Gb of memory allocation when it is
> running.
>>>
>>> Depending on the configuration of your system, it may be that the
> program
>>> started swapping memory at some point.
>>>
>>> Please give a try at the attached code and let us know what you find.
>>>
>>>
>>> Regards,
>>>
>>>
>>> Luis
>>>
>>>
>>>
>>
>
-----------------------------------------------------------------------------------------------------------------------------------
>>> On Fri, Aug 22, 2008 at 11:19 AM, sara meghellati
>> <sara_meghellati at yahoo.fr>
>>> wrote:
>>>>
>>>> I'm sending again my questions as nobody have answered me.
>>>>
>>>> --- En date de : Ven 22.8.08, sara meghellati
>> <sara_meghellati at yahoo.fr> a
>>>> écrit :
>>>>
>>>> De: sara meghellati <sara_meghellati at yahoo.fr>
>>>> Objet: [Insight-users] Please help:problem with wathershed
>> segmentation
>>>> applied to 3D grayscale Image
>>>> À: "insight itk" <insight-users at itk.org>
>>>> Date: Vendredi 22 Août 2008, 13h48
>>>>
>>>> Dear itk experts,
>>>>
>>>> I'm segmenting a volume (3D grayscale image) using watershed
>> method
>>>> inspired from the WatershedSegmentation1
>>>>
>>>> (2D RGB image as input)example provided within itk.
>>>>
>>>> My code is well working for 2D grayscale images but when I change
>>>>
>>>> the dimension to 3, the code
>>>> still running as it get stuck in a
>>>>
>>>> loop!! I wait for more than 18min but no results!! Is it normal
>>>>
>>>> that this kind of segmentation takes age to give the result in 3d
>>>>
>>>> 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?
>>>>
>>>> I pass my code bellow. In this example I used the 3D data provided
>>>>
>>>> in http://public.kitware.com/pub/itk/Data/LiverTumor/.
>>>>
>>>> #include <iostream>
>>>>
>>>> #include "itkImage.h"
>>>>
>>>> #include "itkGradientAnisotropicDiffusionImageFilter.h"
>>>
>>> #include "itkGradientMagnitudeImageFilter.h"
>>>
>>> #include "itkWatershedImageFilter.h"
>>>
>>> #include "itkImageFileReader.h"
>>>
>>> #include "itkImageFileWriter.h"
>>>
>>> #include "itkVectorCastImageFilter.h"
>>>
>>> #include "itkUnaryFunctorImageFilter.h"
>>>
>>> #include "itkScalarToRGBPixelFunctor.h"
>>>
>>>
>>>
>>> #include "itkVTKImageExport.h"
>>>
>>> #include "itkVTKImageImport.h"
>>>
>>>
>>>
>>> #include "vtkImageData.h"
>>>
>>> #include "vtkImageImport.h"
>>>
>>> #include "vtkImageExport.h"
>>>
>>> #include "vtkImageActor.h"
>>>
>>> #include "vtkRenderer.h"
>>>
>>> #include "vtkRenderWindow.h"
>>>
>>> #include "vtkRenderWindowInteractor.h"
>>>
>>> #include "vtkInteractorStyleTrackballCamera.h"
>>>
>>> #include "vtkImageShiftScale.h"
>>>
>>>
>>>
>>> // This function will connect the given itk::VTKImageExport filter to
> the
>>> given vtkImageImport filter.
>>>
>>> template <typename ITK_Exporter, typename VTK_Importer>
>>>
>>> void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
>>>
>>> {
>>>
>>>
>>>
>>
>
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
>>>
>>>
>>>
>>
>
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
>>>
>>>
>> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
>>>
>>> importer->SetSpacingCallback(exporter->GetSpacingCallback());
>>>
>>> importer->SetOriginCallback(exporter->GetOriginCallback());
>>>
>>>
>> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
>>>
>>>
>>>
>>
>
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
>>>
>>>
>>>
>>
>
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
>>>
>>>
>> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
>>>
>>>
>> importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
>>>
>>>
>>
> importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
>>>
>>> importer->SetCallbackUserData(exporter->GetCallbackUserData());
>>>
>>> }
>>>
>>>
>>>
>>> int main( )
>>>
>>> {
>>>
>>> typedef itk::Image<float, 3> ImageType;
>>>
>>> typedef itk::Image<unsigned long, 3> LabeledImageType;
>>>
>>> typedef itk::Image<float, 3> ScalarImageType;
>>>
>>> // for visualization purposes
>>>
>>> typedef itk::RGBPixel<unsigned char> RGBPixelType;
>>>
>>> typedef itk::Image<RGBPixelType, 3> RGBImageType;
>>>
>>>
>>>
>>> typedef itk::ImageFileReader<ImageType> FileReaderType;
>>>
>>> typedef itk::GradientAnisotropicDiffusionImageFilter<ImageType,
>>> ImageType> DiffusionFilterType;
>>>
>>> typedef itk::GradientMagnitudeImageFilter<ImageType,ImageType>
>>> GradientMagnitudeFilterType;
>>>
>>> typedef itk::WatershedImageFilter<ScalarImageType>
>>> WatershedFilterType;
>>>
>>> typedef itk::ImageFileWriter<RGBImageType> FileWriterType;
>>>
>>>
>>>
>>> FileReaderType::Pointer reader = FileReaderType::New
>>>
>>> reader->SetFileName( "c:/images/3DImages/Patient01.mhd"
>> );
>>>
>>>
>> //reader->SetFileName("c:/Images/BrainProtonDensitySlice.png");
>>>
>>>
>>>
>>> DiffusionFilterType::Pointer diffusion =
> DiffusionFilterType::New();
>>>
>>> diffusion->SetNumberOfIterations( atoi("10") );
>>>
>>> diffusion->SetConductanceParameter( atof("2.0") );
>>>
>>> diffusion->SetTimeStep(0.0625);
>>>
>>>
>>>
>>> GradientMagnitudeFilterType::Pointer gradient =
>>> GradientMagnitudeFilterType::New();
>>>
>>>
>>>
>>> WatershedFilterType::Pointer watershed =
> WatershedFilterType::New();
>>>
>>> watershed->SetLevel( atof("0.15") );
>>>
>>> watershed->SetThreshold( atof("0.001") );
>>>
>>> typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long>
>>> ColorMapFunctorType;
>>>
>>> typedef itk::UnaryFunctorImageFilter<LabeledImageType,
>>> RGBImageType, ColorMapFunctorType> ColorMapFilterType;
>>>
>>> ColorMapFilterType::Pointer colormapper =
> ColorMapFilterType::New();
>>>
>>>
>>>
>>> FileWriterType::Pointer writer = FileWriterType::New();
>>>
>>> writer->SetFileName("c:/Images/WatershedSegImg.mhd");
>>>
>>>
>>>
>>> diffusion->SetInput(reader->GetOutput());
>>>
>>> gradient->SetInput(diffusion->GetOutput());
>>>
>>> watershed->SetInput(gradient->GetOutput());
>>>
>>> colormapper->SetInput(watershed->GetOutput());
>>>
>>> writer->SetInput(colormapper->GetOutput());
>>>
>>> writer->Update();
>>>
>>>
>>>
>>> try
>>>
>>> {
>>>
>>> writer->Update();
>>>
>>> }
>>>
>>> catch (itk::ExceptionObject &e)
>>>
>>> {
>>>
>>> std::cerr << e << std::endl;
>>>
>>> }
>>>
>>>
>>>
>>> return 0;
>>>
>>>
>>>
>>> }
>>>
>>> Thanks
>>>
>>> Sara
>>
>>
>> ------------------------------------------------------------------------
>> Envoyé avec Yahoo! Mail
>>
>
<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>.
>> Une boite mail plus intelligente.
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list