[Insight-users] difficulties on watershed for gray Images

Luis Ibanez luis.ibanez at kitware.com
Fri Jul 16 12:01:28 EDT 2004



Hi Anis,


1) Your program is throwing an exception.

    Please, get used to add try/catch blocks
    as a routing practice when you program
    with ITK.  *All* error management in ITK
    is done through C++ exceptions. If you
    don't catch the exceptions, you will never
    see the error messages that ITK is producing
    in order to help you identify the sources
    of problems.



2) The exception in question is being thrown
    when you attempt to save the output image
    in PNG format.

    The reason is that the output of the
    Watershed filter is an image of Labels,
    and they are encoded in an "unsigned long"
    image.

    PNG *does not* support images with pixels
    of "unsigned long", that is pixels of 32 bits.

    You can easily get around this by saving the
    output image in formats such as MetaImage or VTK.



Regards,


    Luis



--------------
sd d wrote:

> I tried to modify the code of watershed segmentation given in the 
> examples,but i have 19 warnings then an abnormal termination when 
> running: WatershedSegmentation Image.png Resultat.png
> Someone can help me, please?
> here is the code.
> 
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> 
> 
> #include <iostream>
> 
> #include "itkGradientAnisotropicDiffusionImageFilter.h"
> #include "itkGradientMagnitudeImageFilter.h"
> #include "itkWatershedImageFilter.h"
> 
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkUnaryFunctorImageFilter.h"
> //#include "itkScalarToRGBPixelFunctor.h"
> int main( int argc, char *argv[] )
> {
> if (argc < 3 )
>     {
>     std::cerr << "Missing Parameters " << std::endl;
>     std::cerr << "Usage: " << argv[0];
>     std::cerr << " inputImage outputImage " << std::endl;
>     return 1;
>     }
> //import sys;
> 
> 
> 	typedef unsigned char   PixelType;
>   typedef itk::Image<PixelType, 2>    ImageType;
>   typedef itk::Image<unsigned long, 2>   LabeledImageType;
>   typedef itk::Image<float, 2>           ScalarImageType;
> 
>   typedef itk::ImageFileReader<ScalarImageType> FileReaderType;
>   typedef itk::GradientAnisotropicDiffusionImageFilter<ScalarImageType,
>     ScalarImageType>  DiffusionFilterType;
>  // typedef itk::GradientMagnitudeImageFilter<ScalarImageType> ScalarMagnitudeFilterType; 
> 	typedef itk::GradientMagnitudeImageFilter<ScalarImageType,ScalarImageType> GradientMagnitudeFilterType; 
>   typedef itk::WatershedImageFilter<ScalarImageType> WatershedFilterType;
>   // Software Guide : EndCodeSnippet
> 
>   //  typedef itk::ImageFileWriter<ImageType> FileWriterType;
>   typedef itk::Image< unsigned long, 2> OutputImageType;
> 	typedef itk::ImageFileWriter< OutputImageType > FileWriterType;
> 
> 
> 
>   FileReaderType::Pointer reader = FileReaderType::New();
> 	reader->SetFileName( argv[1] );
> 	DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
> //diffusion = itk.itkGradientAnisotropicDiffusionImageFilterF2F2_New();
> diffusion->SetInput(reader->GetOutput());
> diffusion->SetTimeStep(0.0625);
> diffusion->SetConductanceParameter(9.0);
> diffusion->SetNumberOfIterations(  5 );
> GradientMagnitudeFilterType:: Pointer gradient =GradientMagnitudeFilterType::New();
> //gradient = itk->itkGradientMagnitudeImageFilterF2F2_New();
> gradient->SetInput(diffusion->GetOutput());
> WatershedFilterType::Pointer watershed = WatershedFilterType::New();
> //watershed = itk->itkWatershedImageFilterF2_New();
> watershed->SetInput(gradient->GetOutput());
> watershed->SetThreshold(0.1);
> watershed->SetLevel(0.6);
> 
> //writer = itk->itkImageFileWriterUL2_New();
> FileWriterType::Pointer writer = FileWriterType::New();
> writer->SetFileName( argv[2] );
> writer->SetInput( watershed->GetOutput()  );
> writer->Update();}
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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