def setUp(self): np.random.seed(1234) self.data_3D = np.random.random((2, 64, 56, 48)) self.data_2D = np.random.random((2, 64, 56)) self.factor = (0.75, 1.25) self.d_3D = augment_contrast(self.data_3D, contrast_range=self.factor, preserve_range=False, per_channel=False) self.d_2D = augment_contrast(self.data_2D, contrast_range=self.factor, preserve_range=False, per_channel=False)
def constrast_augment(data): ''' 对比度增广 :return: ''' result = augment_contrast(data) return result
def __call__(self, **data_dict): data_dict['data'] = augment_contrast( data_dict['data'], contrast_range=self.contrast_range, preserve_range=self.preserve_range, per_channel=self.per_channel) return data_dict
def __call__(self, **data_dict): for b in range(len(data_dict[self.data_key])): if np.random.uniform() < self.p_per_sample: data_dict[self.data_key][b] = augment_contrast(data_dict[self.data_key][b], contrast_range=self.contrast_range, preserve_range=self.preserve_range, per_channel=self.per_channel) return data_dict
def contrast_augmentation_generator(generator, contrast_range=(0.75, 1.25), preserve_range=True, per_channel=True): warn("using deprecated generator contrast_augmentation_generator", Warning) # if contrast_range[0] is <1 and contrast_range[2] is >1 then it will do 50:50 (reduce, increase contrast) # preserve_range will cut off values that due to contrast enhancement get over/below the original minimum/maximum of the data # per_channel does the contrast enhancement separately for each channel for data_dict in generator: data_dict['data'] = augment_contrast(data_dict['data'], contrast_range=contrast_range, preserve_range=preserve_range, per_channel=per_channel) yield data_dict
def __call__(self, **data_dict): data_dict['data'] = augment_contrast(data_dict[self.data_key], contrast_range=self.contrast_range, preserve_range=self.preserve_range, per_channel=self.per_channel) return data_dict