@@ -14,7 +14,7 @@ class Geometric(Augmentation):
14
14
:type scale: tuple, optional
15
15
:param translation: Pair of values determining x and y translation value.
16
16
The translation value will be in percentage of the image size if the value is in between 0 - 1:
17
- x (int) = image width * x (float and 0 - 1)
17
+ x (int) = image width * x (float and 0 - 1);
18
18
y (int) = image height * y (float and 0 - 1)
19
19
:type translation: tuple, optional
20
20
:param fliplr: Flag to flip image in left right direction.
@@ -23,9 +23,9 @@ class Geometric(Augmentation):
23
23
:type flipud: int, optional
24
24
:param crop: Tuple of 4 (x0, y0, xn, yn) to crop section of image.
25
25
The value will be in percentage of the image size if the value is in between 0 - 1:
26
- x0 (int) = image width * x0 (float and 0 - 1)
27
- y0 (int) = image height * y0 (float and 0 - 1)
28
- xn (int) = image width * xn (float and 0 - 1)
26
+ x0 (int) = image width * x0 (float and 0 - 1);
27
+ y0 (int) = image height * y0 (float and 0 - 1);
28
+ xn (int) = image width * xn (float and 0 - 1);
29
29
yn (int) = image height * yn (float and 0 - 1)
30
30
:type crop: tuple, optional
31
31
:param rotate_range: Pair of ints determining the range from which to sample
@@ -35,9 +35,9 @@ class Geometric(Augmentation):
35
35
:type randomize: int, optional
36
36
:param padding: Padding amount on each (left, right, top, bottom) side.
37
37
The padding amount will be in percentage of the image size if the value is in between 0 - 1:
38
- left (int) = image width * left (float and 0 - 1)
39
- right (int) = image height * right (float and 0 - 1)
40
- top (int) = image width * top (float and 0 - 1)
38
+ left (int) = image width * left (float and 0 - 1);
39
+ right (int) = image height * right (float and 0 - 1);
40
+ top (int) = image width * top (float and 0 - 1);
41
41
bottom (int) = image height * bottom (float and 0 - 1)
42
42
:type padding: tuple, optional
43
43
:param padding_type: Padding methods, select from fill,duplicate and mirror.
@@ -123,10 +123,14 @@ def __call__(self, image, layer=None, force=False):
123
123
ysize , xsize = image .shape [:2 ]
124
124
xstart , ystart , xend , yend = self .crop
125
125
126
- if xstart < 1 and ystart < 1 and (xend <= 1 and xend > 0 ) and (yend <= 1 and yend > 0 ):
126
+ # when value is float and in between 0-1, scale it with image size
127
+ if xstart >= 0 and xstart <= 1 and isinstance (xstart , float ):
127
128
xstart = int (xstart * xsize )
129
+ if ystart >= 0 and ystart <= 1 and isinstance (ystart , float ):
128
130
ystart = int (ystart * ysize )
131
+ if xend >= 0 and xend <= 1 and isinstance (xend , float ):
129
132
xend = int (xend * xsize )
133
+ if yend >= 0 and yend <= 1 and isinstance (yend , float ):
130
134
yend = int (yend * ysize )
131
135
132
136
# when value is set to -1, it takes image size
@@ -152,7 +156,7 @@ def __call__(self, image, layer=None, force=False):
152
156
# get image size
153
157
ysize , xsize = image .shape [:2 ]
154
158
# convert percentage into pixel amount
155
- if self .padding [0 ] < 1 :
159
+ if self .padding [0 ] <= 1 and isinstance ( self . padding [ 0 ], float ) :
156
160
self .padding = list (self .padding )
157
161
self .padding [0 ] = int (self .padding [0 ] * xsize )
158
162
@@ -176,7 +180,7 @@ def __call__(self, image, layer=None, force=False):
176
180
# get image size
177
181
ysize , xsize = image .shape [:2 ]
178
182
# convert percentage into pixel amount
179
- if self .padding [1 ] < 1 :
183
+ if self .padding [1 ] <= 1 and isinstance ( self . padding [ 1 ], float ) :
180
184
self .padding = list (self .padding )
181
185
self .padding [1 ] = int (self .padding [1 ] * xsize )
182
186
@@ -200,7 +204,7 @@ def __call__(self, image, layer=None, force=False):
200
204
# get image size
201
205
ysize , xsize = image .shape [:2 ]
202
206
# convert percentage into pixel amount
203
- if self .padding [2 ] < 1 :
207
+ if self .padding [2 ] <= 1 and isinstance ( self . padding [ 2 ], float ) :
204
208
self .padding = list (self .padding )
205
209
self .padding [2 ] = int (self .padding [2 ] * ysize )
206
210
@@ -224,7 +228,7 @@ def __call__(self, image, layer=None, force=False):
224
228
# get image size
225
229
ysize , xsize = image .shape [:2 ]
226
230
# convert percentage into pixel amount
227
- if self .padding [3 ] < 1 :
231
+ if self .padding [3 ] <= 1 and isinstance ( self . padding [ 3 ], float ) :
228
232
self .padding = list (self .padding )
229
233
self .padding [3 ] = int (self .padding [3 ] * ysize )
230
234
@@ -244,6 +248,10 @@ def __call__(self, image, layer=None, force=False):
244
248
image = np .concatenate ([image , image_padding ], axis = 0 )
245
249
246
250
# resize based on scale
251
+ # remove negative value (if any)
252
+ self .scale = list (self .scale )
253
+ self .scale [0 ] = abs (self .scale [0 ])
254
+ self .scale [1 ] = abs (self .scale [1 ])
247
255
if self .scale [1 ] != 1 and self .scale [0 ] != 1 :
248
256
scale = random .uniform (self .scale [0 ], self .scale [1 ])
249
257
if scale > 0 :
@@ -256,10 +264,10 @@ def __call__(self, image, layer=None, force=False):
256
264
if self .translation [0 ] != 0 or self .translation [1 ] != 0 :
257
265
258
266
ysize , xsize = image .shape [:2 ]
259
- if self .translation [0 ] < 1 and self .translation [0 ] > - 1 :
267
+ if self .translation [0 ] <= 1 and self .translation [0 ] >= - 1 and isinstance ( self . translation [ 0 ], float ) :
260
268
self .translation = list (self .translation )
261
269
self .translation [0 ] = int (self .translation [0 ] * xsize )
262
- if self .translation [1 ] < 1 and self .translation [1 ] > - 1 :
270
+ if self .translation [1 ] <= 1 and self .translation [1 ] >= - 1 and isinstance ( self . translation [ 1 ], float ) :
263
271
self .translation = list (self .translation )
264
272
self .translation [1 ] = int (self .translation [1 ] * ysize )
265
273
0 commit comments