[vtkusers] connecting vtkKWImage & vtkKWImageIO to itkFilters

Sergio Aguirre sergio.aguirre at gmail.com
Fri Mar 20 21:27:39 EDT 2009


Bryn

Thank you for the tip. I successfully connected the pipelines using the
itkGDCM dicom series reader then used a itkcurvatureflowimagefilter and
finally connected the ITK image to the vtk pipeline without writing an XML
file using the vtkKWImage class and its SetITKImageBase.

A section of thecode is listed below for my future reference =)

I also reviewed the code you sugested for picking seed points.
http://www.vision.ee.ethz.ch/~blloyd/ImageViewer/<http://www.vision.ee.ethz.ch/%7Eblloyd/ImageViewer/>

I could not build the project I think the tar file is missing the Qt files
and then I got some additional errors. My question is, I noticed that you
write a xxx.txt file of the seeds you select with this application.

Do you later on read the seed.txt file in ITK? or can you export the seeds
from VTK to ITK?

Thank you again.

Sergio



  char fname[] = "/home/echopixel/Desktop/engine/code/seed/images";
// DICOM READER
  typedef unsigned short    PixelType;
  const unsigned int      Dimension = 3;

  typedef itk::Image< 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->SetDirectory( fname );

  try
    {
    std::cout << std::endl << "The directory: " << std::endl;
    std::cout << std::endl << fname << std::endl << std::endl;
    std::cout << "Contains the following DICOM Series: ";
    std::cout << std::endl << std::endl;

    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 )
      {
      std::cout << seriesItr->c_str() << std::endl;
      seriesItr++;
      }

    std::string seriesIdentifier;

    if( argc > 3 ) // If no optional series identifier
      {
      seriesIdentifier = argv[3];
      }
    else
      {
      seriesIdentifier = seriesUID.begin()->c_str();
      }

    std::cout << std::endl << std::endl;
    std::cout << "Now reading series: " << std::endl << std::endl;
    std::cout << seriesIdentifier << std::endl;
    std::cout << std::endl << std::endl;

    typedef std::vector< std::string >   FileNamesContainer;
    FileNamesContainer fileNames;
    fileNames = nameGenerator->GetFileNames( seriesIdentifier );

    reader->SetFileNames( fileNames );
    try
      {      //reader is handler to image stack (volume)
      reader->Update();        // reader contaisn VOLUME stack as ITK Image
      }
    catch (itk::ExceptionObject &ex)
      {        //ctach any errors and print on screen
      std::cout << ex << std::endl;
      }

    }     // END OF TRY that Identified Series and led to TRY that triggers
reading.
  catch (itk::ExceptionObject &ex)
  {    // catch any errors and print on screen.
   std::cout << ex << std::endl;
  }

  //Because CT Scanning has some offsets we must account for them - Slope
and Intercept
   double intercept = dicomIO->GetRescaleIntercept();
   double slope = dicomIO->GetRescaleSlope();

   std::cout << "Rescale Intercept value: " << intercept << endl;
   std::cout << "Rescale Slope value: " << slope << endl;
  // image = reader image is ITK image contains volume stack
  ImageType::Pointer image = reader->GetOutput();
  //Get original stack parameters ie SIZE X 512 Y 512 Z 400+ slices
  ImageType::RegionType inputRegion = image->GetLargestPossibleRegion();
  ImageType::SizeType size = inputRegion.GetSize();

  int Xmax = size[0];
  int Ymax = size[1];
  int Zmax = size[2];
    // Ajust Slope & Intercept Values to each VOXEL - Operate on same image
through iterator IN
    typedef itk::ImageRegionIterator< ImageType > IteratorType;
    IteratorType in( image, image->GetRequestedRegion() );
    // For each voxel in stack - pointed by IN incorporate slope and rescale
    for ( in.GoToBegin(); !in.IsAtEnd(); ++in) {
        in.Set( (in.Value() * slope) + (abs(intercept)));
    }

// DICOM READER
// itk filter
  itk::CurvatureFlowImageFilter<ImageType,ImageType>::Pointer cf =
itk::CurvatureFlowImageFilter<ImageType,ImageType>::New();
  cf->SetInput( reader->GetOutput() );
  //cf->SetInput(image);
  std::cout << "Now doing ITK-Curvature Flow: " << std::endl << std::endl;
  cf->SetTimeStep(0.25);
  cf->SetNumberOfIterations(10);
  cf->Update();

  vtkKWImage *kwImage = vtkKWImage::New();
  kwImage->SetITKImageBase(cf->GetOutput());

  vtkImageData *vtkImage = kwImage->GetVTKImage();

  double range[2];
  vtkImage->GetScalarRange(range);

  vtkImageShiftScale* shifter = vtkImageShiftScale::New();
  shifter->SetShift(-1.0*range[0]);
  shifter->SetScale(255.0/(range[1]-range[0]));
  shifter->SetOutputScalarTypeToUnsignedChar();
  shifter->SetInput(vtkImage);
  shifter->ReleaseDataFlagOff();
  shifter->Update();

  vtkImageViewer2 *ImageViewer = vtkImageViewer2::New();
  ImageViewer->SetInput(shifter->GetOutput());
  ImageViewer->SetColorLevel(127);
  ImageViewer->SetColorWindow(255);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090320/57e396c3/attachment.htm>


More information about the vtkusers mailing list