我正在研究医学图像正是 CT 扫描图像,有一种读取此类图像的方法,还有另一种重采样方法,两种方法的代码如下所示:
def load_itk_image(filename):
# read infos from route
itkimage = sitk.ReadImage(filename)
# read imagearray
numpyImage = sitk.GetArrayFromImage(itkimage)
# read coords
# the given coords and spacing comes: x, y, z and we should transfer it to z, y, x
numpyOrigin = np.array(list(reversed(itkimage.GetOrigin())))
numpySpacing = np.array(list(reversed(itkimage.GetSpacing())))
return numpyImage, numpyOrigin, numpySpacing
def resample(image,oldspacing,newspacing):
start_time = time.time()
resize_factor = np.array(oldspacing).astype(np.float)/np.array(newspacing).astype(np.float)
new_real_shape = image.shape * resize_factor
new_shape = np.round(new_real_shape)
real_resize_factor = new_shape/image.shape
image = scipy.ndimage.interpolation.zoom(image, real_resize_factor, mode = "nearest")
print("%s time takes in seconds" % (time.time() - start_time))
return np.array(image)
我的问题是,重新采样功能需要大量时间来重新采样一张 2d 图像大约需要 30 秒,为什么要花这么多时间?有什么方法可以减少重采样时间?