yuj*_*ao 7 python resize numpy scipy simpleitk
我知道有一个函数scipy.ndimage.zoom可以调整 3D 体积的大小\重新采样,但那是针对 numpy.array 的,而且它的速度非常慢。因此,我用ResampleImageFilterfromSimpleITK代替。我认为基于 C++ simpleitk 工作得更快。
但是使用 simpleitk 重新采样有一个小缺陷。ResampleImageFilter适用于SimpleITK.Image,但不适用于numpy.array,因此进行进一步操作非常不方便。还有其他方法可以对 3D 体积进行重新采样吗?
编辑
为什么我有这个担忧是因为我想利用 SimpleITK 重采样的快速速度,同时我想保持代码干净。例如,我需要对一个卷进行二进制阈值,然后对整个事物进行重新采样。所以这就是我的解决方案
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
Run Code Online (Sandbox Code Playgroud)
但事实上,使用 numpy 进行二进制阈值的逻辑索引要简单得多,这将使我的代码更加紧凑。
总而言之,我想充分利用 SimpleITK 重采样,但有些操作可以通过 numpy 更好地完成,然后我的代码与 SimpleITK 和 numpy 都有点交织在一起。我认为这不是一件好事。