[Insight-users] Reading an mhd file with unknown pixel type

David Doria daviddoria at gmail.com
Wed Dec 1 12:23:45 EST 2010


GetNumberOfComponents() was the function I was looking for. Now that I
have the component type and the number of them, I want to construct a
:

typedef itk::CovariantVector<pixelType, numberOfComponents> ImageType;

However, the compiler won't allow this, I'm assuming because pixelType
and numberOfComponents are not known at compile time. Is there a
better way than a giant switch statement with every possible pixel
type:

  const ScalarPixelType pixelType = imageIO->GetComponentType();
  const int numberOfComponents = imageIO->GetNumberOfComponents();

  if(pixelType == itk::ImageIOBase::DOUBLE && numberOfComponents == 4)
    {
    typedef itk::CovariantVector<double, 4> ImageType;
    }
  else if(numberOfComponents == 5)
....

And this construction also assumes that I know I wanted an
itk::CovariantVector - what if I have no idea about the type?

Thanks,

David


More information about the Insight-users mailing list