[Insight-developers] Cannot read/write vector images with ITK image IO?

Joshua Cates cates@sci.utah.edu
Mon, 31 Mar 2003 13:15:56 -0700 (MST)


Here's one for the IO experts out there,

I can't figure out how to read/write an image of floating point vectors
using the itk image IO classes.  I've tried the method in Software Guide
section 6.5 and also using RawImageIO.


Here are the major roadblocks I've encountered thus far:


1) ImageIO does not compile with vector types.

The following code, for example, will not compile:

 typedef itk::Vector< float, 7 > Vector7PixelType;
 typedef itk::Image< Vector7PixelType, 3 > Vector7ImageType;

 typedef itk::ImageFileReader< Vector7ImageType >  ReaderType;

 ReaderType::Pointer reader = ReaderType::New();

The problem is that some IO classes expect several methods and typedefs
that are not defined for all multiple-component pixel types.
Specifically, the vector class is missing the following:


 typedef T ComponentType;

 static int GetNumberOfComponents(){ return NVectorDimension;}

  void SetNthComponent(int c, const ComponentType& v)
    {  this->operator[](c) = v; }


( Any objections to my adding these methods to itk::Vector? )


2) The method

  bool ImageIOBase::SetPixelType(const std::type_info& ptype) 

enumerates pixel types and throws an exception if a type is not listed.  
This prevents me from even using RawImageIO to write vector image.  Why is 
SetPixelType being called when RawImageIO itself defines the pixel type?

  typedef itk::RawImageIO< Vector6PixelType, 3 > OutputIOType;  
  OutputIOType::Pointer outputIO = OutputIOType::New();
  outputIO->SetFileDimensionality( 3 ); // Not sure which of these 
  outputIO->SetNumberOfDimensions( 3 ); // two methods to call.
  outputIO->SetHeaderSize( 0 );
  outputIO->SetDimensions(0, 148);
  outputIO->SetDimensions(1, 190);
  outputIO->SetDimensions(2, 160);
  outputIO->SetSpacing(0, 1);
  outputIO->SetSpacing(1, 1);
  outputIO->SetSpacing(2, 1);
  outputIO->SetFileTypeToBinary();
  outputIO->SetByteOrderToBigEndian();
  outputIO->SetNumberOfComponents( 6 );
  outputIO->SetComponentType( OutputIOType::FLOAT );

  WriterType::Pointer writer = WriterType::New();
  writer->SetInput( input );
  writer->SetFileName( argv[2] );
  writer->SetImageIO( outputIO );


On Write(), the above code yields the error

 File: /home/sci/cates/Insight/Code/IO/itkImageIOBase.cxx
 Line: 249
 Description: itk::ERROR: RawImageIO(0x816af78): Pixel type currently not 
supported.


Strangely, I am able to _read_ a vector image of multiple components using
RawImageIO.  Why can I read vectors but not write them?

  typedef itk::RawImageIO< Vector7PixelType, 3 > InputIOType;
  
  InputIOType::Pointer inputIO = InputIOType::New();
  inputIO->SetFileDimensionality( 3 );  // Not sure which method
  inputIO->SetNumberOfDimensions( 3 );  // to call.
  inputIO->SetHeaderSize( 0 );
  inputIO->SetDimensions(0, 148);
  inputIO->SetDimensions(1, 190);
  inputIO->SetDimensions(2, 160);
  inputIO->SetSpacing(0, 1);
  inputIO->SetSpacing(1, 1);
  inputIO->SetSpacing(2, 1);
  inputIO->SetFileTypeToBinary();
  inputIO->SetByteOrderToBigEndian();
  inputIO->SetNumberOfComponents( 7 );
  inputIO->SetComponentType( InputIOType::FLOAT );
  
  
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
  reader->SetImageIO(inputIO);
  

Thanks for any help on this.

Josh.


______________________________
 Josh Cates			
 School of Computer Science	
 University of Utah
 Email: cates@sci.utah.edu
 Phone: (801) 587-7697
 URL:   http://www.sci.utah.edu/~cates