What is the best way to do assign values or slices to indexed arrays in SimpleITK?
Example (1): Assigning a 2D slice to an indexed 2D slice in a 3D volume
In NumPy, we can do the following assignment to the index arrays:
import numpy as np
nda = np.ones((64, 256,256))
nda[0,:,:] = 2*nda[0,:,:]
The same operation in SimpleITK,
import SimpleITK as sitk
image = sitk.GetImageFromArray(nda)
image[:,:,0] = 2*image[:,:,0]
gives the following error:
IndexError Traceback (most recent call last)
<ipython-input-18-4649e90a4ea5> in <module>
----> 1 image[:,:,0] = 2*image[:,:,0]
~/anaconda3/lib/python3.7/site-packages/SimpleITK/SimpleITK.py in __setitem__(self, idx, value)
4690
4691 # the index parameter was an invalid set of objects
-> 4692 raise IndexError("invalid index")
4693
4694
IndexError: invalid index
Example (2): Assigning a value an indexed 2D slice in a 3D volume The following operation in NumPy,
nda[0,:,:] = 2
n SimpleITK,
image[:,:,0] = 2
gives the same Index error as in Example (1).