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

Joshua Cates cates@sci.utah.edu
Mon, 31 Mar 2003 14:31:18 -0700 (MST)


The SetPixel method imposes limitations on image IO by requiring the pixel
type to be one of a list of pixel-type/component-type/number-of-components
combinations from a big switch statement (see itkImageIOBase.cxx line
140-255).  This means that if you want to write a pixel type not
enumerated in that list (such as itk::Vector<float, 6>) you have to modify
the ITK source code--even if you are using RawImageIO.

Looks like SetPixel is only an automatic way to set the NumberOfComponents
and the ComponentType based on PixelType?  This is not necessary in the
case of RawImageIO because NumberOfComponents and ComponentType ivars can
be set directly by the user (as in the code below).

I propose that SetPixel be called by RawImageIO (and ImageFileWriter)  
only if the NumberOfComponents and ComponentType ivars have not already
been set by the user.

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


On Mon, 31 Mar 2003, Joshua Cates wrote:

> 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
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>