[Insight-users] watershed segmentation in own function

G G greenlander1986 at gmail.com
Tue Mar 1 05:17:06 EST 2011


Hi Luis,
I tried to write funcion, which return image after image segmentation. I
have this code:

        typedef float              PixelType;
        const   unsigned int                      InputDimension = 3;

        typedef itk::Image< PixelType,  InputDimension >     ImageType;
        typedef  itk::ImageFileReader< ImageType >   ReaderType;

        ReaderType::Pointer reader = ReaderType::New();
        reader->SetFileName( this->settings.getInputPath().c_str() );

        const   unsigned int                      OutputDimension = 3;

        typedef itk::RGBPixel<unsigned char>      RGBPixelType;    // ws
        typedef itk::Image< RGBPixelType, OutputDimension >
OutputImageType; // ws

        WriterType::Pointer writer = WriterType::New();
        writer->SetFileName( this->settings.getOutputPath().c_str() );

        OutputImageType::Pointer output = OutputImageType::New();
            output = this->segmentationCC<OutputImageType::Pointer,
ImageType, OutputImageType, ImageType::Pointer>(reader->GetOutput());
        writer->SetInput(output);
        try
        {
            writer->Update();
            //writer->UpdateLargestPossibleRegion();
            //writer->UpdateOutputData(output);
        }
        catch (itk::ExceptionObject &e)
        {
            this->settings.setLogMessage("Chyba pri zapisu do souboru");
            cerr << e << endl;
            this->settings.setIsOK(false);
            return;
        }


then I have to show function segmentationCC:

    template<typename TOutputImageTypePointer, typename TImageType, typename
TRGBImageType, typename TInput> TOutputImageTypePointer
IOCompute::segmentationCC(TInput input)
    {
          typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
TImageType, TImageType > GradientMagnitudeFilterType;
          GradientMagnitudeFilterType::Pointer gradienMagnitudeFilter =
GradientMagnitudeFilterType::New();
          gradienMagnitudeFilter->SetInput( input );
          gradienMagnitudeFilter->SetSigma( 1.0 );


          typedef  itk::WatershedImageFilter< TImageType >
WatershedFilterType;
          WatershedFilterType::Pointer watershedFilter =
WatershedFilterType::New();
          watershedFilter->SetInput( gradienMagnitudeFilter->GetOutput() );
          watershedFilter->SetThreshold( 0.01 );
          watershedFilter->SetLevel(     0.15 );

          typedef itk::Functor::ScalarToRGBPixelFunctor< unsigned long >
ColorMapFunctorType;

          typedef WatershedFilterType::OutputImageType  LabeledImageType;

          typedef itk::UnaryFunctorImageFilter<
                                        LabeledImageType,
                                        TRGBImageType,
                                        ColorMapFunctorType
                                                        >
ColorMapFilterType;

          ColorMapFilterType::Pointer colorMapFilter =
ColorMapFilterType::New();

          colorMapFilter->SetInput(  watershedFilter->GetOutput() );

          TOutputImageTypePointer output = colorMapFilter->GetOutput();
          return output;
    }



when I use writer->Update();
I have exception


itk::ExceptionObject (00A3F388)
Location: "void __thiscall itk::ImageFileWriter<class itk::Image<class
itk::RGBPixel<unsigned char>,3> >::Write(void)"
File: c:\itkrel\src\insight\code\io\itkImageFileWriter.txx
Line: 271
Description: itk::ERROR: ImageFileWriter(00B513B8): Largest possible region
does not fully contain requested paste IO regionPaste IO region:
ImageIORegion (00A3F3F8)
  Dimension: 3
  Index: 0 0 0
  Size: 0 0 0
Largest possible region: ImageRegion (00A3F3DC)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [0, 0, 0]


or when I have writer->UpdateLargestPossibleRegion(); then no exception, but
any writter output file :'-(

Please help me or give some advice, I am desperate...
Thanks a lot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110301/5f7556a2/attachment.htm>


More information about the Insight-users mailing list