Exemple #1
0
    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
Exemple #2
0
    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
Exemple #3
0
 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
Exemple #4
0
 def apply_transform(self, sample: Subject) -> dict:
     for image_dict in sample.get_images(intensity_only=False):
         image_dict[DATA] = F.interpolate(image_dict[DATA].unsqueeze(0),
                                          size=(SIZE, SIZE, SIZE))
         image_dict[DATA] = image_dict[DATA].squeeze(0)
     return sample
Exemple #5
0
 def apply_transform(self, sample: Subject) -> dict:
     for image_dict in sample.get_images(intensity_only=False):
         image_dict[DATA] = image_dict[DATA].squeeze().unsqueeze(0)
     return sample