I have a 3D image read in to SimpleITK (using python) from a NIfTI file, take each axial slice, do something with it and re-insert the new 2D slice into a 3D volume with the (hopefully) appropriate dimensions. For example,
output = sitk.Image(original.GetSize(), sitk.sitkFloat32)
output.CopyInformation(original)
for z in numpy.arange(original.GetDepth()):
image = original[:,:,z]
<< Do Something in SimpleITK>>
<< Produce a new 2D image = newimage >>
output[:,:,z] = newimage
The final step is throwing an error
In [???]: (executing line ??? of "code.py")
Traceback (most recent call last):
File "code.py", line ???, in <module>
output[:,:,z] = newimage
File "/Library/Python/2.7/site-packages/SimpleITK-0.8.1-py2.7-macosx-10.10-intel.egg/SimpleITK/SimpleITK.py", line 3894, in __setitem__
raise IndexError("invalid index")
IndexError: invalid index
What is the correct syntax (or set of commands) to complete the final step in my for loop?