def image_postprocessing(self, image): """ Processes input image files. Blurs, crops, pads, and normalizes according to the parameters. :param image: The sitk image. :return: The processed sitk image. """ if self.image_gaussian_blur_sigma > 0: image = gaussian(image, [self.image_gaussian_blur_sigma, self.image_gaussian_blur_sigma]) image_float = sitk.Cast(image, sitk.sitkFloat32) image_float = normalize_robust_sitk(image_float, (-1, 1), consideration_factors=self.normalization_consideration_factors) return image_float
def data_sources(self, iterator, cached, use_landmarks=True, image_extension='.nii.gz'): """ Returns the data sources that load data. { 'image_datasource:' ImageDataSource that loads the image files. 'landmarks_datasource:' LandmarkDataSource that loads the landmark coordinates. } :param iterator: The iterator node object. :param cached: If True, use CachedImageDataSource instead of ImageDataSource. :param use_landmarks: If True, create a landmarks datasource. :param image_extension: The extension of the image files. :return: A dict of data sources. """ if self.smoothing_sigma is not None and self.smoothing_sigma > 0: preprocessing = lambda x: sitk.Cast( gaussian(x, self.smoothing_sigma), sitk.sitkInt16) else: preprocessing = None if cached: image_datasource = CachedImageDataSource( self.image_base_folder, '', '', image_extension, preprocessing=preprocessing, cache_maxsize=25000, name='image_datasource', parents=[iterator]) else: image_datasource = ImageDataSource(self.image_base_folder, '', '', image_extension, preprocessing=preprocessing, name='image_datasource', parents=[iterator]) data_sources_dict = {} data_sources_dict['image_datasource'] = image_datasource if use_landmarks: landmark_datasource = LandmarkDataSource( self.point_list_file_name, self.num_landmarks, self.dim, name='landmarks_datasource', parents=[iterator]) data_sources_dict['landmarks_datasource'] = landmark_datasource return data_sources_dict
def image_preprocessing(self, image): if self.image_gaussian_blur_sigma > 0: image = gaussian(image, self.image_gaussian_blur_sigma) if self.crop_image_size is not None: image = sitk.Crop(image, self.crop_image_size, self.crop_image_size) image.SetOrigin([0] * image.GetDimension()) if self.pad_image: pad_size = image.GetSize() pad_size = [int(s / 2) for s in pad_size] image = sitk.MirrorPad(image, pad_size, pad_size) image_float = sitk.Cast(image, sitk.sitkFloat32) image_float = normalize_robust_sitk( image_float, (-1, 1), consideration_factors=self.normalization_consideration_factors) return image_float
def image_postprocessing(self, image): """ Processes input image files. Blurs, crops, pads, and normalizes according to the parameters. :param image: The sitk image. :return: The processed sitk image. """ if self.image_gaussian_blur_sigma > 0: image = gaussian(image, [self.image_gaussian_blur_sigma, self.image_gaussian_blur_sigma]) if self.crop_image_size is not None: image = sitk.Crop(image, self.crop_image_size, self.crop_image_size) if self.pad_image: pad_size = image.GetSize() pad_size = [int(s / 2) for s in pad_size] image = sitk.MirrorPad(image, pad_size, pad_size) image_float = sitk.Cast(image, sitk.sitkFloat32) image_float = normalize_robust_sitk(image_float, (-1, 1), consideration_factors=self.normalization_consideration_factors) return image_float
def image_preprocessing(self, image): if self.image_gaussian_sigma > 0.0: return gaussian(image, self.image_gaussian_sigma) else: return image