https://blog.csdn.net/weixin_42338058/article/details/101517918
def resize_image_itk(itkimage, newSize=None, newSpacing=None, resamplemethod=sitk.sitkBSpline):
"""
image resize withe sitk resampleImageFilter
:param itkimage: sitk.Image
:param newSize:
:param newSpacing: such as [1,1,1]
:param resamplemethod:
:return:
"""
resampler = sitk.ResampleImageFilter()
originSpcaing = itkimage.GetSpacing()
originSize = itkimage.GetSize()
if newSpacing :
newSpacing = np.array(newSpacing, float)
factor = newSpacing / originSpcaing
newSize = originSize / factor
elif newSize:
newSize = np.array(newSize, float)
factor = originSize / newSize
newSpacing = originSpcaing * factor
newSize = newSize.astype(np.int)
newSpacing = newSize.astype(np.int)
resampler.SetReferenceImage(itkimage) # 将输出的大小、原点、间距和方向设置为itkimage
resampler.SetOutputSpacing(newSpacing.tolist()) # 设置输出图像间距
resampler.SetSize(newSize.tolist()) # 设置输出图像大小
resampler.SetTransform(sitk.Transform(3, sitk.sitkIdentity))
resampler.SetInterpolator(resamplemethod)
itkimgResampled = resampler.Execute(itkimage)
return itkimgResampled
网友评论