def apply_transform(self, sample: Subject) -> dict: bspline_params = self.get_params( self.num_control_points, self.max_displacement, self.num_locked_borders, ) random_parameters_dict = {'coarse_grid': bspline_params} if not self.is_tensor: sample.check_consistent_shape() for image_dict in sample.get_images(intensity_only=False): if image_dict[TYPE] == LABEL: interpolation = Interpolation.NEAREST else: interpolation = self.interpolation image_dict[DATA] = self.apply_bspline_transform( image_dict[DATA], image_dict[AFFINE], bspline_params, interpolation, ) sample.add_transform(self, random_parameters_dict) else: sample = self.apply_bspline_transform( sample, np.identity(4), bspline_params, self.interpolation ) return sample
def apply_transform(self, sample: Subject) -> dict: scaling_params, rotation_params = self.get_params( self.scales, self.degrees, self.isotropic) random_parameters_dict = { 'scaling': scaling_params, 'rotation': rotation_params, } if not self.is_tensor: sample.check_consistent_shape() for image_dict in sample.get_images(intensity_only=False): if image_dict[TYPE] == LABEL: interpolation = Interpolation.NEAREST else: interpolation = self.interpolation image_dict[DATA] = self.apply_affine_transform( image_dict[DATA], image_dict[AFFINE], scaling_params, rotation_params, interpolation, ) sample.add_transform(self, random_parameters_dict) else: sample = self.apply_affine_transform( sample, np.identity(4), scaling_params, rotation_params, self.interpolation, ) return sample
def apply_transform(self, sample: Subject) -> dict: axes_to_flip_hot = self.get_params(self.axes, self.flip_probability) random_parameters_dict = {'axes': axes_to_flip_hot} if self.is_tensor: return self.flip_dimensions(sample, axes_to_flip_hot) else: for image_dict in sample.get_images(intensity_only=False): tensor = image_dict[DATA] image_dict[DATA] = self.flip_dimensions(tensor, axes_to_flip_hot) sample.add_transform(self, random_parameters_dict) return sample
def apply_transform(self, sample: Subject) -> dict: random_parameters_images_dict = {} std = self.get_params(self.std_range) if not self.is_tensor: sample.check_consistent_shape() for image_name, image_dict in sample.get_images_dict().items(): random_parameters_dict = {'std': std} random_parameters_images_dict[image_name] = random_parameters_dict image_dict[DATA] = add_noise(image_dict[DATA], std) sample.add_transform(self, random_parameters_images_dict) else: sample = add_noise(sample, std) return sample