def vessel_enhancement(sample, **kwargs): """Apply morphology closing for enhancing vessel structure.""" # size of structural element, chosen to be 11 so that is bigger than the # largest scale of vessels within dataset selem_radius = kwargs.get('selem_radius', 11) @adapt_rgb(each_channel) def channel_closing(img): img_closed = morphology.closing(img, selem=morphology.disk(selem_radius)) return img_closed def enhancing(img): img = np.array(img) img_closed = channel_closing(img) num_channels = np.shape(img_closed)[-1] img_closed_channel_mean = np.reshape( img_closed, (-1, num_channels)).mean(0).reshape(1, 1, num_channels) img = img - img_closed + img_closed_channel_mean return Image.fromarray(img.astype(np.uint8)) sample = image_only_process(enhancing)(sample) return sample
def random_adjust_saturation(sample, **kwargs): """Randomly apply saturation adjustment for RGB image data of a sample.""" saturation_factor_range = kwargs.get('saturation_factor_range', (0.8, 1.2)) saturation_factor = random.uniform(*saturation_factor_range) sample = image_only_process( lambda img: TF.adjust_saturation(img, saturation_factor))(sample) return sample
def random_adjust_gamma(sample, **kwargs): """Randomly apply gamma adjustment for RGB image data of a sample.""" gamma_range = kwargs.get('gamma_range', (0.8, 1.2)) gamma = random.uniform(*gamma_range) sample = image_only_process(lambda img: TF.adjust_gamma(img, gamma))( sample) return sample
def random_adjust_contrast(sample, **kwargs): """Randomly apply contrast adjustment for RGB image data of a sample.""" contrast_factor_range = kwargs.get('contrast_factor_range', (0.8, 1.2)) contrast_factor = random.uniform(*contrast_factor_range) sample = image_only_process( lambda img: TF.adjust_contrast(img, contrast_factor))(sample) return sample
def random_adjust_brightness(sample, **kwargs): """Randomly apply brightness adjustment for RGB image data of a sample.""" brightness_factor_range = kwargs.get('brightness_factor_range', (0.8, 1.2)) brightness_factor = random.uniform(*brightness_factor_range) sample = image_only_process( lambda img: TF.adjust_brightness(img, brightness_factor))(sample) return sample
def normalization(sample, **kwargs): """Apply channel wise normalize of image data of a sample.""" channel_mean = kwargs.get('channel_mean', (0.5, 0.5, 0.5)) channel_std = kwargs.get('channel_std', (0.5, 0.5, 0.5)) sample = image_only_process(lambda img: TF.to_pil_image( TF.normalize(TF.to_tensor(img), channel_mean, channel_std)))(sample) return sample