Python SimpleITK.AffineTransform() Examples
The following are 30
code examples of SimpleITK.AffineTransform().
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: rotation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 7 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ if self.dim == 2: self.current_angles = [float_uniform(-self.random_angles[0], self.random_angles[0])] elif self.dim == 3: # rotate by same random angle in each dimension if len(self.random_angles) == 1: angle = float_uniform(-self.random_angles[0], self.random_angles[0]) self.current_angles = [angle] * self.dim else: # rotate by individual angle in each dimension self.current_angles = [float_uniform(-self.random_angles[i], self.random_angles[i]) for i in range(self.dim)] return self.get_rotation_transform(self.dim, self.current_angles)
Example #2
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 7 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Must contain either 'image', or 'input_size' and 'input_spacing', which define the input image physical space. :return: The sitk.AffineTransform(). """ input_size, input_spacing, _, _ = self.get_image_size_spacing_direction_origin(**kwargs) current_scale = [] for i in range(self.dim): if self.output_size[i] is None or self.output_spacing[i] is None: continue else: current_scale.append((input_size[i] * input_spacing[i]) / (self.output_size[i] * self.output_spacing[i])) max_scale = max(current_scale) current_scale = [] for i in range(self.dim): if i in self.ignore_dim: current_scale.append(1.0) else: current_scale.append(max_scale) return self.get_scale_transform(self.dim, current_scale)
Example #3
Source File: flip.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 7 votes |
def get_flip_transform(dim, flip_axes): """ Returns the sitk transform based on the given parameters. :param dim: The dimension. :param flip_axes: List of flip indizes for each dimension. A True entry indicates a dimension to flip. :return: The sitk.AffineTransform(). """ assert len(flip_axes) == dim, 'flip_axes must have length that is equal to dimension.' # a flip is implemented by scaling the image axis by -1.0 scale_factors = [-1.0 if f else 1.0 for f in flip_axes] t = sitk.AffineTransform(dim) t.Scale(scale_factors) return t
Example #4
Source File: io.py From torchio with MIT License | 6 votes |
def _matrix_to_itk_transform(matrix, dimensions=3): matrix = _to_itk_convention(matrix) rotation = matrix[:dimensions, :dimensions].ravel().tolist() translation = matrix[:dimensions, 3].tolist() transform = sitk.AffineTransform(rotation, translation) return transform
Example #5
Source File: intra_stack_registration.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _get_TPP_transform(self, slice_sitk): origin_3D_sitk = np.array(slice_sitk.GetOrigin()) direction_3D_sitk = np.array(slice_sitk.GetDirection()) T_PP = sitk.AffineTransform(3) T_PP.SetMatrix(direction_3D_sitk) T_PP.SetTranslation(origin_3D_sitk) T_PP = sitk.AffineTransform(T_PP.GetInverse()) return T_PP
Example #6
Source File: slice.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_directory(self): return self._dir_input # Get current affine transformation defining the spatial position in # physical space of slice # \return affine transformation, sitk.AffineTransform object
Example #7
Source File: rotation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ _, _, input_direction, _ = self.get_image_size_spacing_direction_origin(**kwargs) inverse_input_direction = list(np.array(input_direction).reshape([self.dim, self.dim]).flatten()) t = sitk.AffineTransform(self.dim) t.SetMatrix(inverse_input_direction) return t
Example #8
Source File: rotation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ return self.get_rotation_transform(self.dim, self.current_angles)
Example #9
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ current_scale = [self.output_spacing[i] for i in range(self.dim)] return self.get_scale_transform(self.dim, current_scale)
Example #10
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ current_scale = [1 / self.output_spacing[i] for i in range(self.dim)] return self.get_scale_transform(self.dim, current_scale)
Example #11
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Must contain either 'image', or 'input_size' and 'input_spacing', which define the input image physical space. :return: The sitk.AffineTransform(). """ input_size, input_spacing, _, _ = self.get_image_size_spacing_direction_origin(**kwargs) current_scale = [input_spacing[i] for i in range(self.dim)] return self.get_scale_transform(self.dim, current_scale)
Example #12
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Must contain either 'image', or 'input_size' and 'input_spacing', which define the input image physical space. :return: The sitk.AffineTransform(). """ input_size, input_spacing, _, _ = self.get_image_size_spacing_direction_origin(**kwargs) current_scale = [1 / input_spacing[i] for i in range(self.dim)] return self.get_scale_transform(self.dim, current_scale)
Example #13
Source File: stack.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_filename(self): return self._filename # Get history history of affine transforms, i.e. encoded spatial # position+orientation of slice, and rigid motion estimates of slice # obtained in the course of the registration/reconstruction process # \return list of sitk.AffineTransform and sitk.Euler3DTransform objects
Example #14
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ scale = 1.0 + float_uniform(-self.random_scale, self.random_scale) current_scale = [] for i in range(self.dim): if i in self.ignore_dim: current_scale.append(1.0) else: current_scale.append(scale) return self.get_scale_transform(self.dim, current_scale)
Example #15
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ current_scale = [1.0 + float_uniform(-self.random_scale[i], self.random_scale[i]) for i in range(len(self.random_scale))] return self.get_scale_transform(self.dim, current_scale)
Example #16
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ return self.get_scale_transform(self.dim, self.current_scale)
Example #17
Source File: scale.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get_scale_transform(dim, scale): """ Returns the sitk transform based on the given parameters. :param dim: The dimension. :param scale: List of scale factors for each dimension. :return: The sitk.AffineTransform(). """ if isinstance(scale, list) or isinstance(scale, tuple): assert len(scale) == dim, 'Length of scale must be equal to dim.' s = sitk.AffineTransform(dim) s.Scale(scale) return s
Example #18
Source File: common.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def create_composite(dim, transformations, merge_affine=False): """ Creates a composite sitk transform based on a list of sitk transforms. :param dim: The dimension of the transformation. :param transformations: A list of sitk transforms. :param merge_affine: If true, merge affine transformations before calculating the composite transformation. :return: The composite sitk transform. """ if merge_affine: merged_transformations = [] combined_matrix = None for transformation in transformations: if isinstance(transformation, sitk.AffineTransform): if combined_matrix is None: combined_matrix = np.eye(dim + 1) current_matrix = get_affine_homogeneous_matrix(dim, transformation) combined_matrix = current_matrix @ combined_matrix else: if combined_matrix is not None: matrix, translation = get_affine_matrix_and_translation(dim, combined_matrix) combined_affine_transform = sitk.AffineTransform(dim) combined_affine_transform.SetMatrix(matrix) combined_affine_transform.SetTranslation(translation) merged_transformations.append(combined_affine_transform) merged_transformations.append(transformation) combined_matrix = None if combined_matrix is not None: matrix, translation = get_affine_matrix_and_translation(dim, combined_matrix) combined_affine_transform = sitk.AffineTransform(dim) combined_affine_transform.SetMatrix(matrix) combined_affine_transform.SetTranslation(translation) merged_transformations.append(combined_affine_transform) transformations = merged_transformations compos = sitk.Transform(dim, sitk.sitkIdentity) for transformation in transformations: compos.AddTransform(transformation) return compos
Example #19
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: These parameters are given to self.get_output_center(). :return: The sitk.AffineTransform(). """ output_center = self.get_output_center(**kwargs) negative_output_center = [-o for o in output_center] return self.get_translate_transform(self.dim, negative_output_center)
Example #20
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: These parameters are given to self.get_output_center(). :return: The sitk.AffineTransform(). """ output_center = self.get_output_center(**kwargs) return self.get_translate_transform(self.dim, output_center)
Example #21
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Must contain either 'image', or 'input_size' and 'input_spacing', which define the input image physical space. :return: The sitk.AffineTransform(). """ input_center = self.get_input_center(**kwargs) negative_input_center = [-i for i in input_center] return self.get_translate_transform(self.dim, negative_input_center)
Example #22
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Must contain either 'image', or 'input_size' and 'input_spacing', which define the input image physical space. :return: The sitk.AffineTransform(). """ input_center = self.get_input_center(**kwargs) return self.get_translate_transform(self.dim, input_center)
Example #23
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get_input_center(self, **kwargs): """ Returns the input center based on either the parameters defined by the initializer or by **kwargs. The function uses the result of self.get_image_size_spacing_direction_origin(**kwargs) to define the output_center for each entry of output_size and output_spacing that is None. :param kwargs: Must contain either 'image', or 'input_size' and 'input_spacing', which define the input image physical space. :return: The sitk.AffineTransform(). """ input_size, input_spacing, input_direction, input_origin = self.get_image_size_spacing_direction_origin(**kwargs) # -1 is important, as it is always the center pixel. input_size_half = [(input_size[i] - 1) * 0.5 for i in range(self.dim)] return self.index_to_physical_point(input_size_half, input_origin, input_spacing, input_direction)
Example #24
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ return self.get_translate_transform(self.dim, self.current_offset)
Example #25
Source File: translation.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get_translate_transform(self, dim, offset): """ Returns the sitk transform based on the given parameters. :param dim: The dimension. :param offset: List of offsets for each dimension. :return: The sitk.AffineTransform(). """ assert len(offset) == dim, 'Length of offset must be equal to dim.' t = sitk.AffineTransform(dim) offset_with_used_dimensions_only = [o if used else 0 for used, o in zip(self.used_dimensions, offset)] t.Translate(offset_with_used_dimensions_only) return t
Example #26
Source File: flip.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ if len(self.random_flip_axes_probs) == 1: current_flip_axes = bool(bool_bernoulli(p=self.random_flip_axes_probs[0])) current_flip_axes = [current_flip_axes] * self.dim else: # scale by individual factor in each dimension current_flip_axes = [bool(bool_bernoulli(p=self.random_flip_axes_probs[i])) for i in range(self.dim)] return self.get_flip_transform(self.dim, current_flip_axes)
Example #27
Source File: flip.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def get(self, **kwargs): """ Returns the sitk transform based on the given parameters. :param kwargs: Not used. :return: The sitk.AffineTransform(). """ return self.get_flip_transform(self.dim, self.current_flip_axes)
Example #28
Source File: volumetric_reconstruction_pipeline.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _run(self): ph.print_title("Volume-to-Volume Registration") for i in range(0, len(self._stacks)): txt = "Volume-to-Volume Registration -- " \ "Stack %d/%d" % (i + 1, len(self._stacks)) if self._verbose: ph.print_subtitle(txt) else: ph.print_info(txt) if self._robust: transform_initializer = tinit.TransformInitializer( fixed=self._reference, moving=self._stacks[i], similarity_measure="NCC", refine_pca_initializations=True, ) transform_initializer.run() transform_sitk = transform_initializer.get_transform_sitk() transform_sitk = sitk.AffineTransform( transform_sitk.GetInverse()) else: self._registration_method.set_moving(self._reference) self._registration_method.set_fixed(self._stacks[i]) self._registration_method.run() transform_sitk = self._registration_method.get_registration_transform_sitk() # Update position of stack self._stacks[i].update_motion_correction(transform_sitk) ## # Class to perform Slice-To-Volume registration # \date 2017-08-08 02:30:03+0100 #
Example #29
Source File: intra_stack_registration.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _new_affine_transform_itk(self): return itk.AffineTransform.D2.New() ## # Perform motion correction based on performed registration to get motion # corrected stack and associated slice transforms. # \date 2016-11-21 20:11:53+0000 # # \param self The object # \post self._stack_corrected updated # \post self._slice_transforms_sitk updated #
Example #30
Source File: intra_stack_registration.py From NiftyMIC with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _new_affine_transform_sitk(self): return sitk.AffineTransform(2)