I am trying to change the shape of my 3d array from (66, 47, 21) to \[64, 64, 16\] with the following axis being ( X, Y , Z) .
My 3d array came from CT scan , so the Z axis correspond to the number of slice in my image while X and Y are the 2d dimension
What I have currently done is simply :
image = sitk.ReadImage(filename)
image_array = sitk.GetArrayFromImage(image)
median_shape = \[64, 64, 16\]
resized_image = sitk.Resample(image, median_shape)
resized_array = sitk.GetArrayFromImage(resized_image)
However , apparently it's not how I am suppose to do, because i resample, and so I change my pixel spacing. I just want to find a way to change the shape of my image to median_shape, without changing anything, and without loosing information.
SimpleITK considers an image to be an object in 3d space. So resampling that image with a different Z resolution (21 -> 16), is going to require a different Z spacing to compensate.
If you don't really care about the 3d nature of an image you can always over-write the Z spacing with the SetSpacing method. You would be losing the proper spacing, though.