[Insight-users] ITK to VTK 3D WatershedImageFilter

Yusuf OEZBEK nasil122002 at yahoo.de
Tue May 12 10:33:46 EDT 2009


Hello!

What you have about connection  ITK to VTK said, I have made. But the result is still a 2D image not 3D. How do I change my code so I get 3D image with colors?  
 
My result: 
 http://img246.imageshack.us/my.php?image=watershed.jpg
 
My goal: 
http://www.cs.uni-paderborn.de/fileadmin/Informatik/AG-Domik/bachelor_thesis/bolte/coronary_watershed.jpeg
 
 
Sorry, I am new with ITK.


My codes:


  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 <LabeledImageType> ConnectorType;
//  typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> GradientMagnitudeFilterType;
 
//  GradientMagnitudeFilterType::Pointer magnitudeFilter = GradientMagnitudeFilterType::New();
//  magnitudeFilter->SetInput(reader->GetOutput());

   WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();
   watershedFilter->SetInput( reader->GetOutput() );

   watershedFilter->SetLevel(this->sliderLevelWatershed->value());
   watershedFilter->SetThreshold(this->sliderLevelWatershed->value());

//   ColorMapFilterType::Pointer colorMapFilter = ColorMapFilterType::New();
//   colorMapFilter->SetInput(  watershedFilter->GetOutput() );

       this->displayImage3D->show();
       this->displayImage3D->redraw();

    ConnectorType::Pointer connector = ConnectorType::New();
    connector->SetInput(watershedFilter->GetOutput());


    vtkImageShiftScale *shift = vtkImageShiftScale::New();
    shift->SetInput(connector->GetOutput());
    shift->SetOutputScalarTypeToUnsignedChar();


    vtkImageActor* actor = vtkImageActor::New();
    actor->SetInput(shift->GetOutput());

     camera3D = vtkCamera::New();
     camera3D->SetViewUp(0, 0, -1);
     camera3D->SetPosition(0, 1, 0);
     camera3D->SetFocalPoint(0, 0, 0);
     camera3D->ComputeViewPlaneNormal();
     camera3D->Azimuth(20);

     renderer3DWaterShed = vtkRenderer::New();
     renderWindow3DWaterShed = vtkRenderWindow::New();
     renderWindow3DWaterShed->AddRenderer(renderer3DWaterShed);

        displayImage3D->SetRenderWindow(renderWindow3DWaterShed);
//      displayImage3D->SetInteractorStyle(mode3DWaterShed);
        displayImage3D->Initialize();

       renderer3DWaterShed->AddActor(actor);
       renderer3DWaterShed->SetActiveCamera(camera3D);
       renderer3DWaterShed->ResetCamera();
       camera3D->Dolly(1.3);
       renderer3DWaterShed->ResetCameraClippingRange();
       renderer3DWaterShed->Render();






________________________________
Von: Luis Ibanez <luis.ibanez at kitware.com>
An: ahmet mehmet <nasil122002 at yahoo.de>
CC: vtk-developers at vtk.org; insight-users at itk.org; vtkusers at vtk.org
Gesendet: Dienstag, den 28. April 2009, 18:53:48 Uhr
Betreff: Re: [Insight-users] ITK to VTK 3D WatershedImageFilter



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



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090512/9e528cdc/attachment-0002.htm>


More information about the Insight-users mailing list