Specifying ImageIO when reading a file in Python


#1

With SimpleITK, I can specify ImageIO when reading a file:

image = sitk.ReadImage(filename, sitk.sitkInt16, 'GiplImageIO')

Is there a similar, Pythonic interface for this in itk-5.0rc1? I tried:

img = itk.image_file_reader(FileName=filename, ImageIO=itk.GiplImageIO)

NotImplementedError: Wrong number or type of arguments for overloaded function 'itkImageIOBase_SetFileName'.
  Possible C/C++ prototypes are:
    itkImageIOBase::SetFileName(char const *)
    itkImageIOBase::SetFileName(std::string const &)

itk.imread can take PixelType as an argument, but it still guesses ImageIO from the file extension, which I want to avoid — I’d like to be able to read images always as a certain type, no matter what their file extension is.


(Francois Budin) #2

It should work if you write:

img = itk.image_file_reader(FileName=filename, ImageIO=itk.GiplImageIO.New())

#3

Thank you!