Exemple #1
0
 def spatial_transformation_volumetric_augmented(self, image):
     """
     The spatial image transformation with random augmentation.
     :return: The transformation.
     """
     dim = 3
     transformations_list = [translation.InputCenterToOrigin(dim),
                             scale.FitFixedAr(dim, self.image_size + [None], ignore_dim=[2])]
     if self.scale_factor[0] == 1.0 and self.scale_factor[1] == 1.0:
         # if no scale_factor, randomly shift by certain value
         transformations_list.append(translation.Random(dim, [self.image_size[0] * 0.35, self.image_size[1] * 0.35, 0.0]))
     else:
         # else, randomly move in imag size
         move_factor = [(1.0 - self.scale_factor[i]) * 0.5 for i in [0, 1]]
         transformations_list.append(translation.Random(dim, [self.image_size[0] * move_factor[0], self.image_size[1] * move_factor[1], 0]))
         transformations_list.append(scale.Fixed(dim, self.scale_factor + [1.0]))
     transformations_list.extend([flip.Random(dim, [0.5, 0.5, 0.0]),
                                  rotation.Random(dim, [0., 0., math.pi]),
                                  scale.RandomUniform(dim, 0.25, ignore_dim=[2]),
                                  scale.Random(dim, [0.25, 0.25, 0.0]),
                                  translation.OriginToOutputCenter(dim, self.image_size + [self.num_frames]),
                                  deformation.Output(dim, [6, 6, 4], [10, 10, 0], self.image_size + [self.num_frames])])
     comp = composite.Composite(dim, transformations_list,
                                name='image_transformation_comp',
                                kwparents={'image': image})
     return LambdaNode(lambda comp: sitk.DisplacementFieldTransform(sitk.TransformToDisplacementField(comp, sitk.sitkVectorFloat64, size=self.image_size + [self.num_frames])),
                       name='image_transformation',
                       kwparents={'comp': comp})
Exemple #2
0
 def spatial_transformation_augmented(self, image):
     """
     The spatial image transformation with random augmentation.
     :return: The transformation.
     """
     # bring image to center and fit to AR
     transformations_list = [translation.InputCenterToOrigin(self.dim),
                             scale.FitFixedAr(self.dim, self.image_size)]
     if self.scale_factor[0] == 1.0 and self.scale_factor[1] == 1.0:
         # if no scale_factor, randomly shift by certain value
         transformations_list.append(translation.Random(self.dim, [self.image_size[0] * 0.35, self.image_size[1] * 0.35]))
     else:
         # else, randomly move in imag size
         move_factor = [(1.0 - self.scale_factor[i]) * 0.5 for i in [0, 1]]
         transformations_list.append(translation.Random(self.dim, [self.image_size[0] * move_factor[0], self.image_size[1] * move_factor[1]]))
         transformations_list.append(scale.Fixed(self.dim, self.scale_factor))
     transformations_list.extend([flip.Random(self.dim, [0.5, 0.5]),
                                  rotation.Random(self.dim, [math.pi]),
                                  scale.RandomUniform(self.dim, 0.25),
                                  scale.Random(self.dim, [0.25, 0.25]),
                                  translation.OriginToOutputCenter(self.dim, self.image_size),
                                  deformation.Output(self.dim, [8, 8], 10, self.image_size)])
     comp = composite.Composite(self.dim, transformations_list,
                                name='image_transformation_comp',
                                kwparents={'image': image})
     return LambdaNode(lambda comp: sitk.DisplacementFieldTransform(sitk.TransformToDisplacementField(comp, sitk.sitkVectorFloat64, size=self.image_size)),
                       name='image_transformation',
                       kwparents={'comp': comp})
 def spatial_transformation_augmented(self, iterator, datasources, image_size):
     """
     The spatial image transformation with random augmentation.
     :param datasources: datasources dict.
     :return: The transformation.
     """
     transformation_list = []
     kwparents = {'image': datasources['image'], 'output_size': image_size}
     if self.translate_to_center_landmarks:
         kwparents['start'] = datasources['landmarks_bb_start']
         kwparents['extent'] = datasources['landmarks_bb_extent']
         transformation_list.append(translation.BoundingBoxCenterToOrigin(self.dim, None, self.image_spacing))
     elif self.generate_single_vertebrae or self.generate_single_vertebrae_heatmap:
         single_landmark = LambdaNode(lambda id_dict, landmarks: [landmarks[int(id_dict['landmark_id'])]],
                                      parents=[iterator, datasources['landmarks']])
         kwparents['landmarks'] = single_landmark
         transformation_list.append(landmark.Center(self.dim, True))
         transformation_list.append(translation.Fixed(self.dim, [0, 20, 0]))
     else:
         transformation_list.append(translation.InputCenterToOrigin(self.dim))
     if self.translate_by_random_factor:
         transformation_list.append(translation.RandomCropBoundingBox(self.dim, None, self.image_spacing))
     #    transformation_list.append(translation.RandomFactorInput(self.dim, [0, 0, 0.5], [0, 0, self.image_spacing[2] * image_size[2]]))
     transformation_list.extend([translation.Random(self.dim, [self.random_translation] * self.dim),
                                 rotation.Random(self.dim, [self.random_rotate] * self.dim),
                                 scale.RandomUniform(self.dim, self.random_scale),
                                 scale.Random(self.dim, [self.random_scale] * self.dim),
                                 flip.Random(self.dim, [0.5 if self.random_flip else 0.0, 0.0, 0.0]),
                                 translation.OriginToOutputCenter(self.dim, None, self.image_spacing),
                                 deformation.Output(self.dim, [6, 6, 6], [self.random_deformation] * self.dim, None, self.image_spacing)
                                 ])
     comp = composite.Composite(self.dim, transformation_list, name='image', kwparents=kwparents)
     return LambdaNode(lambda comp, output_size: sitk.DisplacementFieldTransform(sitk.TransformToDisplacementField(comp, sitk.sitkVectorFloat64, size=output_size, outputSpacing=self.image_spacing)),
                       name='image',
                       kwparents={'comp': comp, 'output_size': image_size})
Exemple #4
0
 def spatial_transformation_augmented(self):
     """
     The spatial image transformation with random augmentation.
     :return: The transformation.
     """
     return composite.Composite(self.dim, [
         landmark.Center(self.dim, False),
         translation.Random(self.dim, [20, 20, 20]),
         rotation.Random(self.dim, [0.35, 0.35, 0.35]),
         scale.RandomUniform(self.dim, 0.2),
         scale.Random(self.dim, [0.1, 0.1, 0.1]),
         translation.OriginToOutputCenter(self.dim, self.image_size,
                                          self.image_spacing),
         deformation.Output(self.dim, [8, 8, 8], 15, self.image_size,
                            self.image_spacing)
     ])
Exemple #5
0
 def spatial_transformation_augmented(self, data_sources):
     """
     The spatial image transformation with random augmentation.
     :param data_sources: The data_sources dictionary.
     :return: The transformation.
     """
     return composite.Composite(
         self.dim, [
             translation.InputCenterToOrigin(self.dim),
             translation.Random(self.dim, [10, 10]),
             rotation.Random(self.dim, [0.25]),
             scale.RandomUniform(self.dim, 0.2),
             scale.Random(self.dim, [0.2, 0.2]),
             translation.OriginToOutputCenter(self.dim, self.image_size,
                                              self.image_spacing),
             deformation.Output(self.dim, [5, 5], 10, self.image_size,
                                self.image_spacing)
         ],
         kwparents={'image': data_sources['image_datasource']},
         name='image')
 def spatial_transformation_augmented(self, datasources):
     """
     The spatial image transformation with random augmentation.
     :param datasources: datasources dict.
     :return: The transformation.
     """
     transformation_list = []
     kwparents = {'image': datasources['image']}
     transformation_list.append(translation.InputCenterToOrigin(self.dim))
     transformation_list.extend([
         translation.Random(self.dim, [20, 20, 20]),
         rotation.Random(self.dim, [0.35, 0.35, 0.35]),
         scale.RandomUniform(self.dim, 0.2),
         scale.Random(self.dim, [0.1, 0.1, 0.1]),
         translation.OriginToOutputCenter(self.dim, self.image_size,
                                          self.image_spacing),
         deformation.Output(self.dim, [6, 6, 6], 15, self.image_size,
                            self.image_spacing)
     ])
     return composite.Composite(self.dim,
                                transformation_list,
                                name='image',
                                kwparents=kwparents)