I know there is a function scipy.ndimage.zoom
to resize\resample 3D volumes, but that is for numpy.array and it is notoriously slow. Therefore, I use ResampleImageFilter
from SimpleITK
instead. I think base on C++ simpleitk work much faster.
BUT there is a small flaw using simpleitk to resample. ResampleImageFilter
works on SimpleITK.Image, but not numpy.array, so it is pretty inconvenient to do further operations. Is there any other way to resample 3D volumes?
EDIT
Why I am having this concerns is because I want to take advantage of the fast speed of SimpleITK resampling, and meanwhile I want to keep my code clean.
For example, I need to do binary threshold to a volume and then resample the whole thing. So this is my solution,
binthresh = sitk.BinaryThresholdImageFilter()
... #setting up params for the binthresh
img = binarythresh.Execute(img)
resample = sitk.ResampleImageFilter()
... #setting up params for the resample
img = resample.Execute(img)
arr = sitk.GetArrayFromImage(img)
... # numpy operations on the arr
But in fact, using numpy to do the binary threshold is way simpler with logic indexing, which would make my code way more compact.
So in summary, I want to make the most of SimpleITK resampling, but some operations can be better done by numpy, and then my code gets a bit intertwined with both SimpleITK and numpy. And I dont think that is a good thing.