1
+ from imgaug import augmenters as iaa
2
+
3
+ def Aug100px ():
4
+ """
5
+ Augment 100 pixel images.
6
+ :return:
7
+ """
8
+ aug_seq = iaa .Sequential ([
9
+ #iaa.Crop(px=(0, 15)), # crop images from each side by 0 to 33px (randomly chosen)
10
+ iaa .Fliplr (0.5 ), # horizontally flip 50% of the images
11
+ iaa .Flipud (0.5 ), # horizontally flip 50% of the images
12
+ iaa .GaussianBlur (sigma = (0 , 2.0 )), # blur images with a sigma of 0 to 2.0
13
+ iaa .Multiply ((0.25 , 1.75 ), per_channel = True ),
14
+ iaa .AddToHueAndSaturation ((- 25 , 25 )),
15
+ iaa .Dropout ((0.01 , 0.2 ), per_channel = True ),
16
+ iaa .SaltAndPepper ((0.01 ,0.05 ), per_channel = True ),
17
+ iaa .Affine (
18
+ scale = {"x" : (0.8 , 1.2 ), "y" : (0.8 , 1.2 )}, # scale images to 80-120% of their size, individually per axis
19
+ #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
20
+ rotate = (- 45 , 45 ), # rotate by -45 to +45 degrees
21
+ shear = (- 16 , 16 ), # shear by -16 to +16 degrees
22
+ )
23
+ ])
24
+
25
+ return aug_seq
26
+
27
+ def Aug200px ():
28
+ """
29
+ Augment 200 pixel images.
30
+ :return:
31
+ """
32
+ aug_seq = iaa .Sequential ([
33
+ #iaa.Crop(px=(0, 15)), # crop images from each side by 0 to 33px (randomly chosen)
34
+ iaa .Fliplr (0.5 ), # horizontally flip 50% of the images
35
+ iaa .Flipud (0.5 ), # horizontally flip 50% of the images
36
+ iaa .GaussianBlur (sigma = (0 , 2.0 )), # blur images with a sigma of 0 to 2.0
37
+ iaa .Multiply ((0.25 , 1.75 ), per_channel = True ),
38
+ iaa .AddToHueAndSaturation ((- 25 , 25 )),
39
+ iaa .Dropout ((0.01 , 0.2 ), per_channel = True ),
40
+ iaa .SaltAndPepper ((0.01 ,0.05 ), per_channel = True ),
41
+ iaa .Affine (
42
+ scale = {"x" : (0.8 , 1.2 ), "y" : (0.8 , 1.2 )}, # scale images to 80-120% of their size, individually per axis
43
+ #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
44
+ rotate = (- 45 , 45 ), # rotate by -45 to +45 degrees
45
+ shear = (- 16 , 16 ), # shear by -16 to +16 degrees
46
+ )
47
+ ])
48
+
49
+ return aug_seq
50
+
51
+ def Aug300px ():
52
+ """
53
+ Augment 300 pixel images.
54
+ :return:
55
+ """
56
+ aug_seq = iaa .Sequential ([
57
+ #iaa.Crop(px=(0, 15)), # crop images from each side by 0 to 33px (randomly chosen)
58
+ iaa .Fliplr (0.5 ), # horizontally flip 50% of the images
59
+ iaa .Flipud (0.5 ), # horizontally flip 50% of the images
60
+ iaa .GaussianBlur (sigma = (0 , 2.0 )), # blur images with a sigma of 0 to 2.0
61
+ iaa .Multiply ((0.25 , 1.75 ), per_channel = True ),
62
+ iaa .AddToHueAndSaturation ((- 25 , 25 )),
63
+ iaa .Dropout ((0.01 , 0.2 ), per_channel = True ),
64
+ iaa .SaltAndPepper ((0.01 ,0.05 ), per_channel = True ),
65
+ iaa .Affine (
66
+ scale = {"x" : (0.8 , 1.2 ), "y" : (0.8 , 1.2 )}, # scale images to 80-120% of their size, individually per axis
67
+ #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
68
+ rotate = (- 45 , 45 ), # rotate by -45 to +45 degrees
69
+ shear = (- 16 , 16 ), # shear by -16 to +16 degrees
70
+ )
71
+ ])
72
+
73
+ return aug_seq
74
+
75
+ def Aug400px ():
76
+ """
77
+ Augment 400 pixel images.
78
+ :return:
79
+ """
80
+ aug_seq = iaa .Sequential ([
81
+ #iaa.Crop(px=(0, 15)), # crop images from each side by 0 to 33px (randomly chosen)
82
+ iaa .Fliplr (0.5 ), # horizontally flip 50% of the images
83
+ iaa .Flipud (0.5 ), # horizontally flip 50% of the images
84
+ iaa .GaussianBlur (sigma = (0 , 2.0 )), # blur images with a sigma of 0 to 2.0
85
+ iaa .Multiply ((0.25 , 1.75 ), per_channel = True ),
86
+ iaa .AddToHueAndSaturation ((- 25 , 25 )),
87
+ iaa .Dropout ((0.01 , 0.2 ), per_channel = True ),
88
+ iaa .SaltAndPepper ((0.01 ,0.05 ), per_channel = True ),
89
+ iaa .Affine (
90
+ scale = {"x" : (0.8 , 1.2 ), "y" : (0.8 , 1.2 )}, # scale images to 80-120% of their size, individually per axis
91
+ #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
92
+ rotate = (- 45 , 45 ), # rotate by -45 to +45 degrees
93
+ shear = (- 16 , 16 ), # shear by -16 to +16 degrees
94
+ )
95
+ ])
96
+
97
+ return aug_seq
98
+
99
+ def Aug500px ():
100
+ """
101
+ Augment 500 pixel images.
102
+ :return:
103
+ """
104
+ aug_seq = iaa .Sequential ([
105
+ #iaa.Crop(px=(0, 15)), # crop images from each side by 0 to 33px (randomly chosen)
106
+ iaa .Fliplr (0.5 ), # horizontally flip 50% of the images
107
+ iaa .Flipud (0.5 ), # horizontally flip 50% of the images
108
+ iaa .GaussianBlur (sigma = (0 , 2.0 )), # blur images with a sigma of 0 to 2.0
109
+ iaa .Multiply ((0.25 , 1.75 ), per_channel = True ),
110
+ iaa .AddToHueAndSaturation ((- 25 , 25 )),
111
+ iaa .Dropout ((0.01 , 0.2 ), per_channel = True ),
112
+ iaa .SaltAndPepper ((0.01 ,0.05 ), per_channel = True ),
113
+ iaa .Affine (
114
+ scale = {"x" : (0.8 , 1.2 ), "y" : (0.8 , 1.2 )}, # scale images to 80-120% of their size, individually per axis
115
+ #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
116
+ rotate = (- 45 , 45 ), # rotate by -45 to +45 degrees
117
+ shear = (- 16 , 16 ), # shear by -16 to +16 degrees
118
+ )
119
+ ])
120
+
121
+ return aug_seq
122
+
123
+ def BackgroundAug500px ():
124
+ """
125
+ Augment 500 pixel images.
126
+ :return:
127
+ """
128
+ sometimes = lambda aug : iaa .Sometimes (0.5 , aug )
129
+
130
+ aug_seq = iaa .Sequential ([
131
+ #iaa.Crop(px=(0, 15)), # crop images from each side by 0 to 33px (randomly chosen)
132
+ sometimes (iaa .Fliplr (0.5 )), # horizontally flip 50% of the images
133
+ sometimes (iaa .Flipud (0.5 )), # horizontally flip 50% of the images
134
+ sometimes (iaa .GaussianBlur (sigma = (0 , 2.0 ))), # blur images with a sigma of 0 to 2.0
135
+ sometimes (iaa .Multiply ((0.25 , 1.75 ), per_channel = True )),
136
+ sometimes (iaa .AddToHueAndSaturation ((- 25 , 25 ))),
137
+ sometimes (iaa .Dropout ((0.01 , 0.2 ), per_channel = True )),
138
+ sometimes (iaa .SaltAndPepper ((0.01 ,0.05 ), per_channel = True )),
139
+ sometimes (iaa .Affine (
140
+ scale = {"x" : (0.8 , 1.2 ), "y" : (0.8 , 1.2 )}, # scale images to 80-120% of their size, individually per axis
141
+ #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
142
+ rotate = (- 180 , 180 ), # rotate randomly
143
+ shear = (- 16 , 16 ), # shear by -16 to +16 degrees
144
+ )),
145
+ sometimes (iaa .PerspectiveTransform (scale = (0.01 , 0.1 )))
146
+ ])
147
+
148
+ return aug_seq
0 commit comments