Reading an image with five components

Hi everyone,
I’m trying to read an image with 5 components with itk::ImageFileReader, but it crashes with the following message:
terminate called after throwing an instance of ‘itk::ExceptionObject’
what(): /home/mory/sources/itk/ITK/Modules/IO/ImageBase/include/itkConvertPixelBuffer.hxx:171:
itk::ERROR: No conversion available from 5 components to: 5 components

It works fine with 3 components, but crashes with 5. Is it the expected behaviour ? I’m using ITK v4.13.0, but I would see no problem in upgrading to a newer version if necessary.

Here is the code I use:

#include <itkImage.h>
#include <itkVector.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>

int main(){
typedef itk::Image<itk::Vector<float, 5>, 3> ImageOfVectorsType;

typedef itk::ImageFileReader ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("/home/mory/ThreeDimensionsFiveComponents.mha");
reader->Update();

return EXIT_SUCCESS;
}

Have you tried this example? Does this one work? If yes, what are the main differences to your example?

With the help of a colleague, we found the source of the problem: my image /home/mory/ThreeDimensionsFiveComponents.mha contains vectors of doubles, not of floats, and in that case the itk::ImageFileReader fails to perform the conversion.

1 Like