[vtkusers] [Insight-users] ITK to VTK 3D WatershedImageFilter

Luis Ibanez luis.ibanez at kitware.com
Tue Apr 28 12:53:48 EDT 2009


Hi Ahmet,


You are declaring an ITK+VTK connector of type:

   typedef itk::ImageToVTKImageFilter <ImageType> ConnectorType;

where ImageType is given by

   typedef unsigned char PixelType;
   const unsigned int Dimension = 3;
   typedef itk::OrientedImage< PixelType, Dimension > ImageType;


but you are connecting an image of RGB pixels to it.
(instead of the image of unsigned char that you promised).


What you may want to do is to remove the ITK Coloring filter,
and to pass the image of labels (the output of the watershed)
directly to VTK.

Note that then the ITK+VTK connector, should be of type:

     itk::ImageToVTKImageFilter < LabeledImageType >



   Regards,


       Luis


------------------
ahmet mehmet wrote:
> Hello!
>  
> I wanted my 3D watershed segmentation combine with VTK and to show it in 
> a VTK window. For the connection between ITK and VTK, I used 
> itkImageToVTKImageFilter. But it gives following error. 
>  
>  
> 
> /home/hno4d/Desktop/MIRCIT/MIRCIT.cpp: In member function »virtual void 
> MIRCIT::imageDisplayingWatershed()«:
> /home/hno4d/Desktop/MIRCIT/MIRCIT.cpp:1719: Fehler: keine passende 
> Funktion für Aufruf von 
> »itk::ImageToVTKImageFilter<itk::OrientedImage<unsigned char, 3u> 
>  >::SetInput(itk::Image<itk::RGBPixel<unsigned char>, 3u>*)«
> /home/hno4d/Desktop/MIRCIT/itkImageToVTKImageFilter.txx:79: Anmerkung: 
> Kandidaten sind: void 
> itk::ImageToVTKImageFilter<TInputImage>::SetInput(const TInputImage*) 
> [with TInputImage = itk::OrientedImage<unsigned char, 3u>]
> make[2]: *** [CMakeFiles/MIRCIT.dir/MIRCIT.o] Fehler 1
> make[1]: *** [CMakeFiles/MIRCIT.dir/all] Fehler 2
> make: *** [all] Fehler 2
> 
>  
>  
> How can I use my code with the following ITK VTK connection?
>  
>  
> My code:
>  
>  
> 
> typedef unsigned char PixelType;
> const unsigned int Dimension = 3;
> 
> typedef itk::OrientedImage< PixelType, Dimension > ImageType;
> typedef itk::ImageSeriesReader< ImageType > ReaderType;
> 
> ReaderType::Pointer reader = ReaderType::New();
> 
> typedef itk::GDCMImageIO ImageIOType;
> ImageIOType::Pointer dicomIO = ImageIOType::New();
> 
> reader->SetImageIO( dicomIO );
> typedef itk::GDCMSeriesFileNames NamesGeneratorType;
>  
> NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
> nameGenerator->SetUseSeriesDetails( true );
> nameGenerator->AddSeriesRestriction("0008|0021" );
> nameGenerator->SetDirectory( selectedDirectory);
>  
> typedef std::vector< std::string > SeriesIdContainer;
> const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
> SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
> SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
> while( seriesItr != seriesEnd )
> {
> seriesItr++;
> }
> 
> std::string seriesIdentifier;
> seriesIdentifier = seriesUID.begin()->c_str();
> 
> typedef std::vector< std::string > FileNamesContainer;
> FileNamesContainer fileNames;
> fileNames = nameGenerator->GetFileNames( seriesIdentifier );
> 
> reader->SetFileNames( fileNames );
> reader->Update();
> 
> typedef float InternalPixelType;
> typedef itk::RGBPixel<unsigned char> RGBPixelType;
> typedef itk::Image< RGBPixelType, Dimension > RGBImageType;
> // typedef itk::ImageFileWriter< RGBImageType > WriterType;
> typedef itk::WatershedImageFilter< ImageType > WatershedFilterType;
> typedef itk::Functor::ScalarToRGBPixelFunctor< unsigned long> 
> ColorMapFunctorType;
> typedef WatershedFilterType::OutputImageType LabeledImageType;
> typedef itk::UnaryFunctorImageFilter< 
> LabeledImageType,RGBImageType,ColorMapFunctorType > ColorMapFilterType;
> typedef itk::ImageToVTKImageFilter <ImageType> ConnectorType;
> typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> 
> GradientMagnitudeFilterType;
> 
>  
> GradientMagnitudeFilterType::Pointer magnitudeFilter = 
> GradientMagnitudeFilterType::New();
> magnitudeFilter->SetInput(reader->GetOutput());
> 
>  
> WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();
> watershedFilter->SetInput( magnitudeFilter->GetOutput() );
> watershedFilter->SetThreshold(this->sliderLevelWatershed->value());
> watershedFilter->SetLevel(this->sliderThresholdWatershed->value());
> 
> ColorMapFilterType::Pointer colorMapFilter = ColorMapFilterType::New();
> colorMapFilter->SetInput( watershedFilter->GetOutput() );
> 
> ConnectorType::Pointer connector = ConnectorType::New();
> connector->SetInput(colorMapFilter->GetOutput());
> 
> vtkImageActor* actor = vtkImageActor::New();
> actor->SetInput(connector->GetOutput());
> 
> vtkInteractorStyleImage * interactorStyle = vtkInteractorStyleImage::New();
> 
> vtkRenderer* renderer = vtkRenderer::New();
> vtkRenderWindow* renWin = vtkRenderWindow::New();
> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
> 
> renWin->SetSize(500, 500);
> renWin->AddRenderer(renderer);
> iren->SetRenderWindow(renWin);
> iren->SetInteractorStyle( interactorStyle );
> renderer->AddActor(actor);
> 
> renWin->Render();
> iren->Start();
> 
> Thank you!
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users



More information about the vtkusers mailing list