예제 #1
0
 def data_generators(self, image_post_processing_np):
     """
     Returns the data generators that process one input. See datasources() for dict values.
     :param image_post_processing_np: The np postprocessing function for the image data generator.
     :return: A dict of data generators.
     """
     image_generator = ImageGenerator(
         self.dim,
         self.image_size,
         post_processing_np=image_post_processing_np,
         interpolator='linear',
         resample_default_pixel_value=0,
         data_format=self.data_format,
         resample_sitk_pixel_type=sitk.sitkFloat32,
         np_pixel_type=np.float32)
     if self.downsampling_factor == 1:
         heatmap_post_transformation = None
     else:
         heatmap_post_transformation = scale.Fixed(self.dim,
                                                   self.downsampling_factor)
     landmark_generator = LandmarkGeneratorHeatmap(
         self.dim,
         self.heatmap_size, [1] * self.dim,
         self.sigma,
         scale_factor=1.0,
         normalize_center=True,
         data_format=self.data_format,
         post_transformation=heatmap_post_transformation)
     return {'image': image_generator, 'landmarks': landmark_generator}
예제 #2
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})
예제 #3
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})
예제 #4
0
 def image_transformation_val(self):
     return composite.Composite(self.dim, [
         translation.InputCenterToOrigin(self.dim),
         scale.Fit(self.dim, self.image_size),
         scale.Fixed(self.dim, self.additional_scale),
         translation.OriginToOutputCenter(self.dim, self.image_size)
     ])
예제 #5
0
 def spatial_transformation(self, image):
     """
     The spatial image transformation without random augmentation.
     :return: The transformation.
     """
     return composite.Composite(self.dim,
                                [translation.InputCenterToOrigin(self.dim),
                                 scale.Fit(self.dim, self.image_size),
                                 scale.Fixed(self.dim, self.additional_scale),
                                 translation.OriginToOutputCenter(self.dim, self.image_size)],
                                name='image',
                                kwparents={'image': image})
예제 #6
0
 def data_generators(self, data_sources, transformation,
                     image_post_processing_np):
     """
     Returns the data generators that process one input. See datasources() for dict values.
     :param data_sources: The data_sources dictionary.
     :param transformation: The used transformation.
     :param image_post_processing_np: The np postprocessing function for the image data generator.
     :return: A dict of data generators.
     """
     image_generator = ImageGenerator(
         self.dim,
         self.image_size,
         self.image_spacing,
         post_processing_np=image_post_processing_np,
         interpolator='linear',
         resample_default_pixel_value=0,
         data_format=self.data_format,
         resample_sitk_pixel_type=sitk.sitkFloat32,
         np_pixel_type=np.float32,
         parents=[data_sources['image_datasource'], transformation],
         name='image')
     if self.downsampling_factor == 1:
         heatmap_post_transformation = None
     else:
         heatmap_post_transformation = scale.Fixed(self.dim,
                                                   self.downsampling_factor)
     landmark_generator = LandmarkGenerator(
         self.dim,
         self.heatmap_size,
         self.image_spacing,
         #sigma=1.0,
         #scale_factor=1.0,
         #normalize_center=True,
         data_format=self.data_format,
         post_transformation=heatmap_post_transformation,
         min_max_transformation_distance=30,
         parents=[data_sources['landmark_datasource'], transformation],
         name='landmarks')
     return {'image': image_generator, 'landmarks': landmark_generator}