本文整理汇总了Python中SimpleITK.sitkBSpline方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleITK.sitkBSpline方法的具体用法?Python SimpleITK.sitkBSpline怎么用?Python SimpleITK.sitkBSpline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleITK
的用法示例。
在下文中一共展示了SimpleITK.sitkBSpline方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resample_image
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def resample_image(itk_image, out_spacing=[1.0, 1.0, 1.0], is_label=False):
original_spacing = itk_image.GetSpacing()
original_size = itk_image.GetSize()
out_size = [
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_image.GetDirection())
resample.SetOutputOrigin(itk_image.GetOrigin())
resample.SetTransform(sitk.Transform())
resample.SetDefaultPixelValue(itk_image.GetPixelIDValue())
if is_label:
resample.SetInterpolator(sitk.sitkNearestNeighbor)
else:
resample.SetInterpolator(sitk.sitkBSpline)
return resample.Execute(itk_image)
示例2: resample_image
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def resample_image(itk_image, out_spacing=(1.0, 1.0, 1.0), is_label=False):
original_spacing = itk_image.GetSpacing()
original_size = itk_image.GetSize()
out_size = [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_image.GetDirection())
resample.SetOutputOrigin(itk_image.GetOrigin())
resample.SetTransform(sitk.Transform())
resample.SetDefaultPixelValue(itk_image.GetPixelIDValue())
if is_label:
resample.SetInterpolator(sitk.sitkNearestNeighbor)
else:
resample.SetInterpolator(sitk.sitkBSpline)
return resample.Execute(itk_image)
示例3: reslice_image
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def reslice_image(itk_image, itk_ref, is_label=False):
resample = sitk.ResampleImageFilter()
resample.SetReferenceImage(itk_ref)
if is_label:
resample.SetInterpolator(sitk.sitkNearestNeighbor)
else:
resample.SetInterpolator(sitk.sitkBSpline)
return resample.Execute(itk_image)
示例4: resample_image_to_ref
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def resample_image_to_ref(image, ref, is_label=False, pad_value=0):
"""Resamples an image to match the resolution and size of a given reference image."""
resample = sitk.ResampleImageFilter()
resample.SetReferenceImage(ref)
resample.SetDefaultPixelValue(pad_value)
if is_label:
resample.SetInterpolator(sitk.sitkNearestNeighbor)
else:
#resample.SetInterpolator(sitk.sitkBSpline)
resample.SetInterpolator(sitk.sitkLinear)
return resample.Execute(image)
示例5: resample_image
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def resample_image(image, out_spacing=(1.0, 1.0, 1.0), out_size=None, is_label=False, pad_value=0):
"""Resamples an image to given element spacing and output size."""
original_spacing = np.array(image.GetSpacing())
original_size = np.array(image.GetSize())
if out_size is None:
out_size = np.round(np.array(original_size * original_spacing / np.array(out_spacing))).astype(int)
else:
out_size = np.array(out_size)
original_direction = np.array(image.GetDirection()).reshape(len(original_spacing),-1)
original_center = (np.array(original_size, dtype=float) - 1.0) / 2.0 * original_spacing
out_center = (np.array(out_size, dtype=float) - 1.0) / 2.0 * np.array(out_spacing)
original_center = np.matmul(original_direction, original_center)
out_center = np.matmul(original_direction, out_center)
out_origin = np.array(image.GetOrigin()) + (original_center - out_center)
resample = sitk.ResampleImageFilter()
resample.SetOutputSpacing(out_spacing)
resample.SetSize(out_size.tolist())
resample.SetOutputDirection(image.GetDirection())
resample.SetOutputOrigin(out_origin.tolist())
resample.SetTransform(sitk.Transform())
resample.SetDefaultPixelValue(pad_value)
if is_label:
resample.SetInterpolator(sitk.sitkNearestNeighbor)
else:
#resample.SetInterpolator(sitk.sitkBSpline)
resample.SetInterpolator(sitk.sitkLinear)
return resample.Execute(sitk.Cast(image, sitk.sitkFloat32))
示例6: get_sitk_interpolator
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def get_sitk_interpolator(interpolator):
if interpolator == 'nearest':
return sitk.sitkNearestNeighbor
elif interpolator == 'linear':
return sitk.sitkLinear
elif interpolator == 'cubic':
return sitk.sitkBSpline
elif interpolator == 'label_gaussian':
return sitk.sitkLabelGaussian
elif interpolator == 'gaussian':
return sitk.sitkGaussian
elif interpolator == 'lanczos':
return sitk.sitkLanczosWindowedSinc
else:
raise Exception('invalid interpolator type')
示例7: test_affine_transform_reg_aladin
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkBSpline [as 别名]
def test_affine_transform_reg_aladin(self):
# Read data
filename_fixed = "stack1_rotated_angle_z_is_pi_over_10.nii.gz"
filename_moving = "FetalBrain_reconstruction_3stacks_myAlg.nii.gz"
diff_ref = os.path.join(
DIR_TEST, "stack1_rotated_angle_z_is_pi_over_10_nreg_diff.nii.gz")
moving = st.Stack.from_filename(
os.path.join(self.dir_test_data, filename_moving),
)
fixed = st.Stack.from_filename(
os.path.join(self.dir_test_data, filename_fixed)
)
# Set up NiftyReg
nifty_reg = nreg.RegAladin()
nifty_reg.set_fixed(fixed)
nifty_reg.set_moving(moving)
nifty_reg.set_registration_type("Rigid")
nifty_reg.use_verbose(False)
# Register via NiftyReg
nifty_reg.run()
# Get associated results
affine_transform_sitk = nifty_reg.get_registration_transform_sitk()
moving_warped = nifty_reg.get_warped_moving()
# Get SimpleITK result with "similar" interpolator (NiftyReg does not
# state what interpolator is used but it seems to be BSpline)
moving_warped_sitk = sitk.Resample(
moving.sitk, fixed.sitk, affine_transform_sitk, sitk.sitkBSpline, 0.0, moving.sitk.GetPixelIDValue())
diff_res_sitk = moving_warped.sitk - moving_warped_sitk
sitkh.write_nifti_image_sitk(diff_res_sitk, diff_ref)
diff_ref_sitk = sitk.ReadImage(diff_ref)
res_diff_nda = sitk.GetArrayFromImage(diff_res_sitk - diff_ref_sitk)
self.assertAlmostEqual(
np.linalg.norm(res_diff_nda), 0, places=self.accuracy)