def intensity_postprocessing_mr_random(self, image): """ Intensity postprocessing for MR input. Random augmentation version. :param image: The np input image. :return: The processed image. """ image = change_gamma_unnormalized(image, float_uniform(0.5, 1.5)) image = normalize_robust(image, consideration_factors=(0.1, 0.1)) return ShiftScaleClamp(random_shift=0.6, random_scale=0.6, clamp_min=-1.0)(image)
def intensity_postprocessing_ct_random(self, image): """ Intensity postprocessing for CT input. Random augmentation version. :param image: The np input image. :return: The processed image. """ if not self.normalize_zero_mean_unit_variance: random_lambda = float_uniform(0.9, 1.1) image = change_gamma_unnormalized(image, random_lambda) output = ShiftScaleClamp(shift=0, scale=1 / 2048, random_shift=self.random_intensity_shift, random_scale=self.random_intensity_scale, clamp_min=-1.0, clamp_max=1.0)(image) else: random_lambda = float_uniform(0.9, 1.1) image = change_gamma_unnormalized(image, random_lambda) output = normalize_zero_mean_unit_variance(image) return output
def postprocessing_random(self, image): """ Performs random augmentations of a grayscale image. Augmentation consists of random gamma correction, random intensity shift/scale per video and per frame. :param image: The grayscale image to augment. :return: The augmented grayscale image. """ random_lambda = float_uniform(0.6, 1.4) image = change_gamma_unnormalized(image, random_lambda) image = ShiftScaleClamp(random_shift=0.65, random_scale=0.65)(image) if len(image.shape) == 4: for i in range(image.shape[self.video_frame_stack_axis]): current_slice = [slice(None), slice(None)] current_slice.insert(self.video_frame_stack_axis, slice(i, i + 1)) image[tuple(current_slice)] = ShiftScaleClamp(random_shift=0.1, random_scale=0.1)(image[tuple(current_slice)]) return image