Python SimpleITK.sitkBSpline() Examples
The following are 8
code examples of SimpleITK.sitkBSpline().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
SimpleITK
, or try the search function
.
Example #1
Source File: download_IXI_Guys.py From DLTK with Apache License 2.0 | 8 votes |
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)
Example #2
Source File: download_IXI_HH.py From DLTK with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: download_IXI_Guys.py From DLTK with Apache License 2.0 | 5 votes |
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)
Example #4
Source File: processing.py From istn with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: processing.py From istn with Apache License 2.0 | 5 votes |
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))
Example #6
Source File: sitk_image.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
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')
Example #7
Source File: download_IXI_HH.py From DLTK with Apache License 2.0 | 4 votes |
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)
Example #8
Source File: niftyreg_test.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 4 votes |
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)