Skip to content

Commit 103cbd8

Browse files
committed
Various updates
1. Fixed bugs in geometric and pageborder. 2. Major updates in pencilscribbles to add text based scribbles. 3. Updated archetypes pipelines. 4. Synced python packages between requirements file and install_requires in pypi. 5. Remove python 3.7 and added python 3.11 in the testing workflow.
1 parent 7a13a8d commit 103cbd8

File tree

11 files changed

+435
-148
lines changed

11 files changed

+435
-148
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
main:
1313
strategy:
1414
matrix:
15-
python-version: ['3.7', '3.8', '3.9', '3.10']
15+
python-version: ['3.8', '3.9', '3.10', '3.11']
1616

1717
runs-on: ubuntu-latest
1818
steps:

augraphy/augmentations/geometric.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Geometric(Augmentation):
1414
:type scale: tuple, optional
1515
:param translation: Pair of values determining x and y translation value.
1616
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);
1818
y (int) = image height * y (float and 0 - 1)
1919
:type translation: tuple, optional
2020
:param fliplr: Flag to flip image in left right direction.
@@ -23,9 +23,9 @@ class Geometric(Augmentation):
2323
:type flipud: int, optional
2424
:param crop: Tuple of 4 (x0, y0, xn, yn) to crop section of image.
2525
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);
2929
yn (int) = image height * yn (float and 0 - 1)
3030
:type crop: tuple, optional
3131
:param rotate_range: Pair of ints determining the range from which to sample
@@ -35,9 +35,9 @@ class Geometric(Augmentation):
3535
:type randomize: int, optional
3636
:param padding: Padding amount on each (left, right, top, bottom) side.
3737
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);
4141
bottom (int) = image height * bottom (float and 0 - 1)
4242
:type padding: tuple, optional
4343
:param padding_type: Padding methods, select from fill,duplicate and mirror.
@@ -123,10 +123,14 @@ def __call__(self, image, layer=None, force=False):
123123
ysize, xsize = image.shape[:2]
124124
xstart, ystart, xend, yend = self.crop
125125

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):
127128
xstart = int(xstart * xsize)
129+
if ystart >= 0 and ystart <= 1 and isinstance(ystart, float):
128130
ystart = int(ystart * ysize)
131+
if xend >= 0 and xend <= 1 and isinstance(xend, float):
129132
xend = int(xend * xsize)
133+
if yend >= 0 and yend <= 1 and isinstance(yend, float):
130134
yend = int(yend * ysize)
131135

132136
# when value is set to -1, it takes image size
@@ -152,7 +156,7 @@ def __call__(self, image, layer=None, force=False):
152156
# get image size
153157
ysize, xsize = image.shape[:2]
154158
# convert percentage into pixel amount
155-
if self.padding[0] < 1:
159+
if self.padding[0] <= 1 and isinstance(self.padding[0], float):
156160
self.padding = list(self.padding)
157161
self.padding[0] = int(self.padding[0] * xsize)
158162

@@ -176,7 +180,7 @@ def __call__(self, image, layer=None, force=False):
176180
# get image size
177181
ysize, xsize = image.shape[:2]
178182
# convert percentage into pixel amount
179-
if self.padding[1] < 1:
183+
if self.padding[1] <= 1 and isinstance(self.padding[1], float):
180184
self.padding = list(self.padding)
181185
self.padding[1] = int(self.padding[1] * xsize)
182186

@@ -200,7 +204,7 @@ def __call__(self, image, layer=None, force=False):
200204
# get image size
201205
ysize, xsize = image.shape[:2]
202206
# convert percentage into pixel amount
203-
if self.padding[2] < 1:
207+
if self.padding[2] <= 1 and isinstance(self.padding[2], float):
204208
self.padding = list(self.padding)
205209
self.padding[2] = int(self.padding[2] * ysize)
206210

@@ -224,7 +228,7 @@ def __call__(self, image, layer=None, force=False):
224228
# get image size
225229
ysize, xsize = image.shape[:2]
226230
# convert percentage into pixel amount
227-
if self.padding[3] < 1:
231+
if self.padding[3] <= 1 and isinstance(self.padding[3], float):
228232
self.padding = list(self.padding)
229233
self.padding[3] = int(self.padding[3] * ysize)
230234

@@ -244,6 +248,10 @@ def __call__(self, image, layer=None, force=False):
244248
image = np.concatenate([image, image_padding], axis=0)
245249

246250
# 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])
247255
if self.scale[1] != 1 and self.scale[0] != 1:
248256
scale = random.uniform(self.scale[0], self.scale[1])
249257
if scale > 0:
@@ -256,10 +264,10 @@ def __call__(self, image, layer=None, force=False):
256264
if self.translation[0] != 0 or self.translation[1] != 0:
257265

258266
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):
260268
self.translation = list(self.translation)
261269
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):
263271
self.translation = list(self.translation)
264272
self.translation[1] = int(self.translation[1] * ysize)
265273

augraphy/augmentations/pageborder.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def __call__(self, image, layer=None, force=False):
316316
self.noise_intensity_range[1],
317317
)
318318

319-
if self.width_range[0] < 1:
319+
if self.width_range[0] > 0 and self.width_range[0] <= 1 and isinstance(self.width_range[0], float):
320320
self.width_range = list(self.width_range)
321321
self.width_range[0] = np.ceil(self.width_range[0] * min(height, width))
322322
self.width_range[1] = np.ceil(self.width_range[1] * min(height, width))
@@ -352,7 +352,6 @@ def __call__(self, image, layer=None, force=False):
352352
border = np.flipud(border)
353353
if self.same_page_border:
354354
border_y, border_x = border.shape[:2]
355-
border_image = np.full_like(image, fill_value=255)
356355
border_image[:, :border_x] = border
357356
else:
358357
image_output = np.hstack((border, image))
@@ -363,9 +362,8 @@ def __call__(self, image, layer=None, force=False):
363362
border = np.flipud(border)
364363

365364
if self.same_page_border:
366-
367365
border_y, border_x = border.shape[:2]
368-
border_image[-border_y:, -border_x:] = border
366+
border_image[:, -border_x:] = border
369367
else:
370368
image_output = np.hstack((image, border))
371369

0 commit comments

Comments
 (0)