Hi, I have a probably trivial issue, but I can’t wrap my mind around it.I am trying to slice a 3D image using indexing but I get one slice short of what one would expect. After looking into it, it seems the last slice is always missing. Here’s a simple example using a simple array:
import numpy as np
import SimpleITK as itk
# create
test_array = np.array([0,1,2,3,4]*6).reshape(3,2,5)
test_array = test_array.swapaxes(2,0)
test_array
Out[2]:
array([[[0, 0, 0],
[0, 0, 0]],
[[1, 1, 1],
[1, 1, 1]],
[[2, 2, 2],
[2, 2, 2]],
[[3, 3, 3],
[3, 3, 3]],
[[4, 4, 4],
[4, 4, 4]]])
If we convert this array to an Image and take every second slice in the third dimension and convert it back to a numpy array (for easier visualization), we expect to get an array of size (3,2,3), the same as one would by using the same operation on the array directly. Instead we get this
test_img = itk.GetImageFromArray(test_array)
sliced = test_img[:,:,::2]
sliced_array = itk.GetArrayFromImage(sliced)
sliced_array
Out[3]:
array([[[0, 0, 0],
[0, 0, 0]],
[[2, 2, 2],
[2, 2, 2]]])
So the last slice
[[4,4,4],
[4,4,4]]
is missing.
Is this a bug or am I missing something?