Hello everyone,
I try to resample image 1 (nii) [128,128,128], spacing [1,1,1] to image2 [512,512,476], spacing2 [0.6,0.6,0.6], but I got image as following.
def resample_img(itk_image1, itk_image2, out_spacing=[0.6, 0.6, 0.6]):
original_spacing = itk_image2.GetSpacing()
original_size = itk_image1.GetSize()
out_size = itk_image2.GetSize()
# int(np.round(original_size[0] * (original_spacing[0] / out_spacing[0]))),
# int(np.round(original_size[1] * (original_spacing[1] / out_spacing[1]))),
# int(np.round(original_size[2] * (original_spacing[2] / out_spacing[2])))]
resample = sitk.ResampleImageFilter()
resample.SetOutputSpacing(out_spacing)
resample.SetSize(out_size)
resample.SetOutputDirection(itk_image2.GetDirection())
resample.SetOutputOrigin(itk_image2.GetOrigin())
resample.SetTransform(sitk.Transform())
resample.SetDefaultPixelValue(itk_image2.GetPixelIDValue())
resample.SetInterpolator(sitk.sitkBSpline)
# resample.SetDefaultPixelValue(-1000)
return resample.Execute(itk_image)
re = resample_img(image1, image2)
sitk.WriteImage(re, 're.nii')
Did I miss something? Thanks.