def lighting(): generate_gif("op_global_brightness", [ aug.Brightness(change=i).apply(aug.Sample(lena)).image for i in (.01, .03, .2, .8, .97, .99) ]) generate_gif( "op_radial_gradient", [aug.RadialGradient().apply(aug.Sample(lena)).image for _ in range(5)]) generate_gif( "op_linear_gradient", [aug.LinearGradient().apply(aug.Sample(lena)).image for _ in range(5)]) generate_gif("op_halo", [ aug.HaloEffect(alpha=.6, radius=aug.uniform(.3, .5)).apply( aug.Sample(lena)).image for _ in range(5) ]) generate_gif("op_flashlight", [ aug.Flashlight(alpha=aug.uniform(.2, .6), bg_darkness=aug.uniform(50, 150), radius=aug.uniform(.3, .6)).apply( aug.Sample(lena)).image for _ in range(5) ])
def __init__(self): super(ComplexExamplePipeline, self).__init__() self.seq1 = aug.Sequential( self.affine_ops(), aug.Choice( aug.Stretch(p=.5, x_scale=aug.uniform(.25, .5), y_scale=aug.uniform(.25, .5)), aug.Rotation(p=.5, angle=aug.truncnorm(0., 5., 5., 10.))), aug.GaussianBlur(p=1), ) self.seq2 = aug.Sequential(aug.GaussianBlur(p=1), aug.GaussianBlur(p=1))
def perspective(): generate_gif("op_perspective", [ aug.PerspectiveDistortion().apply(aug.Sample(lena)).image for _ in range(5) ]) generate_gif("op_elastic", [ aug.ElasticDistortion(alpha=aug.uniform(50., 200.), sigma=aug.uniform(2., 10.)).apply( aug.Sample(lena)).image for _ in range(6) ]) generate_gif( "op_grid", [aug.GridDistortion().apply(aug.Sample(lena)).image for _ in range(5)]) generate_gif("op_optical", [ aug.OpticalDistortion(interpolation=cv2.BORDER_REFLECT).apply( aug.Sample(lena.copy())).image for _ in range(5) ])
def __init__(self, angle=aug.uniform(-30, 30), interpolation=cv2.INTER_LINEAR, mode='replicate', change_size=True): self._angle = angle self._interpolation = interpolation self._mode = mode self._change_size = change_size self.mtx = None self.new_width = None self.new_height = None
def __init__(self): super().__init__() self.seq = aug.Sequential( aug.PerspectiveDistortion(p=.5, max_warp=.12), aug.Choice( aug.GridDistortion(num_steps=(10, 10), distort_limit=(.6, 1.4)), # TODO expensive computationally # aug.ElasticTransformation(p=.25, alpha=aug.uniform(20., 120.), # sigma=aug.uniform(8, 20), # alpha_affine_range=aug.uniform(8., 10.)), ), aug.Rotation(p=.25, angle=aug.uniform(-5, 5), mode='replicate'), aug.Zoom(p=.5, margin=.1), )
def __init__(self): super().__init__() self.seq = aug.Sequential( aug.GaussNoise(p=.45, avg=0, std_dev=aug.uniform(0, 40)), aug.SaltNoise(p=.2, percent=aug.uniform(0.0001, 0.0008)), aug.PepperNoise(p=.2, percent=aug.uniform(0.0001, 0.0008)), aug.CutOut(p=.1, size_range=(.05, .15), iterations=aug.uniform(1, 4)), aug.JpegNoise(p=.4, quality=aug.uniform(.1, .5)), aug.Pixelize(p=.4, ratio=aug.uniform(.2, .5)))
def __init__(self): super().__init__() self.seq = aug.Choice( aug.MedianBlur(p=1., ksize_norm=aug.uniform(0., .006)), aug.GaussianBlur(p=1., ksize_norm=aug.uniform(.0, .05), sigma=aug.uniform(1, 5)), aug.MotionBlur(p=1., ksize_norm=aug.uniform(.01, .04)), aug.Choice( aug.VariableBlur(p=1., ksize_norm=aug.uniform(.015, .005), modes=('linear', )), aug.VariableBlur(p=1., ksize_norm=aug.uniform(.01, .005), modes=('radial', ))))
def __init__(self): super().__init__() self.seq = aug.Sequential( aug.Choice( aug.Brightness(p=1., change=aug.uniform(.01, .97)), aug.Choice( aug.LinearGradient(p=1., edge_brightness=(aug.uniform(.0, .05), aug.uniform(.1, .6)), orientation='horizontal'), aug.LinearGradient(p=1., edge_brightness=(aug.uniform(.0, .05), aug.uniform(.1, .6)), orientation='vertical'))), aug.Contrast(p=1., scale=aug.uniform(.5, 1.5)), )
def affine_ops(self): return aug.Sequential( aug.Stretch(p=.5, x_scale=aug.uniform(.25, .5), y_scale=aug.uniform(.25, .5)), aug.Rotation(p=.5, angle=aug.truncnorm(0., 5., 5., 10.)))
def get_operation(self, parameters): for parameter in parameters: if isinstance(parameters, tuple): parameters[parameter] = aug.uniform(*parameter) return self.operation(**parameters)