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.
ndimage.zoom
without much issues, , albeit for small volumes. Are you comparingSimpleITK
andndimage
with similar setups (i.e. excluding loading overhead, same interpolator, etc)? how much faster does it really get? By the way you can get a numpy array withsitk.GetArrayFromImage
– Perlitezoom
with numpy.array is much inferior to the SimpleITK in terms of speed. – Subshrubsitk.ArrayfromImage
to get numpy.array. But since SimpleITK provide a much faster resampling, I prefer to sticking to this. However, using SimpleITK would make my code less consice, I would re-edit my post to state my point. – SubshrubGetArrayViewFromImage
but it turns out that the array_view is read only. Is there a way I can use numpy operation to the array of SimpleITK.Image without copying the volume back and forth as you initially suggeted? – Subshrub