1

I'm using SimpleITK for Python and have created an empty image using NumPy as follows:

import SimpleITK as sitk
import numpy as np

pixels = np.zeros((64, 64))
image = sitk.GetImageFromArray(pixels)

Then, when I try to write the image to file in NIFTI format it complains that it cannot find the method "SetImageIO" on the ImageFileWriter object.

write = sitk.ImageFileWriter()
write.SetFileName('hello.nii.gz')
write.SetImageIO('NiftiImageIO')
write.Execute(image)

Error:

AttributeError: 'ImageFileWriter' object has no attribute 'SetImageIO'

Does anybody know why this is? The C++ docs clearly mention a method "SetImageIO" for ImageFileWriter.

Thanks, Ralph

Ralph
  • 151
  • 11

2 Answers2

3

What version of SimpleITK do you have installed?

This is a new feature with 1.2, so if you have an older version the method will not be available.

blowekamp
  • 1,401
  • 7
  • 7
2

The SimpleITK documentation is sorely lacking, and not all C++ library functions are available in the python package, which complicates a few more things.

However,

sitk.WriteImage(image, "hello.nii.gz")

Will automatically infer the filetype from the string.

Czorio
  • 105
  • 2
  • 7