Skip to content

Commit 282c1f8

Browse files
committed
Fixed default pipeline.
1 parent e9c8917 commit 282c1f8

File tree

4 files changed

+234
-34
lines changed

4 files changed

+234
-34
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ BibTeX:
6767
author = {{The Augraphy Project}},
6868
title = {{Augraphy: an augmentation pipeline for rendering synthetic paper printing, faxing, scanning and copy machine processes}},
6969
url = {https://github.com/sparkfish/augraphy},
70-
version = {7.0.0}
70+
version = {8.0.0}
7171
}
7272
```
7373

augraphy/base/paperfactory.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ def __call__(self, image, layer=None, force=False):
9595
return texture
9696

9797
else:
98-
print("No paper image in the paper directory!")
98+
# future development
99+
"""
100+
if verbose:
101+
print("No paper image in the paper directory!")
102+
"""
103+
pass
99104

100105
def check_paper_edges(self, texture):
101106

augraphy/default/pipeline.py

+226-31
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,261 @@
1111
def default_augraphy_pipeline():
1212

1313
ink_phase = [
14-
Dithering(p=0.5),
15-
InkBleed(p=0.5),
16-
BleedThrough(p=0.5),
17-
Letterpress(p=0.5),
14+
Dithering(
15+
dither=random.choice(["ordered", "floyd-steinberg"]),
16+
order=random.randint(3, 5),
17+
p=0.33,
18+
),
19+
InkBleed(
20+
intensity_range=(0.1, 0.2),
21+
color_range=(0, 16),
22+
kernel_size=random.choice([(7, 7), (5, 5), (3, 3)]),
23+
severity=(0.4, 0.6),
24+
p=0.33,
25+
),
26+
BleedThrough(
27+
intensity_range=(0.1, 0.3),
28+
color_range=(32, 224),
29+
ksize=(17, 17),
30+
sigmaX=1,
31+
alpha=random.uniform(0.1, 0.2),
32+
offsets=(10, 20),
33+
p=0.33,
34+
),
35+
Letterpress(
36+
n_samples=(100, 400),
37+
n_clusters=(200, 400),
38+
std_range=(500, 3000),
39+
value_range=(150, 224),
40+
value_threshold_range=(96, 128),
41+
blur=1,
42+
p=0.33,
43+
),
1844
OneOf(
1945
[
20-
LowInkRandomLines(use_consistent_lines=False),
21-
LowInkRandomLines(use_consistent_lines=True),
22-
LowInkPeriodicLines(use_consistent_lines=False),
23-
LowInkPeriodicLines(use_consistent_lines=True),
46+
LowInkRandomLines(
47+
count_range=(5, 10),
48+
use_consistent_lines=random.choice([True, False]),
49+
noise_probability=0.1,
50+
),
51+
LowInkPeriodicLines(
52+
count_range=(2, 5),
53+
period_range=(16, 32),
54+
use_consistent_lines=random.choice([True, False]),
55+
noise_probability=0.1,
56+
),
2457
],
2558
),
2659
]
2760

2861
paper_phase = [
29-
PaperFactory(p=0.5),
30-
ColorPaper(p=0.5),
31-
WaterMark(p=0.5),
62+
PaperFactory(p=0.33),
63+
ColorPaper(
64+
hue_range=(0, 255),
65+
saturation_range=(10, 40),
66+
p=0.33,
67+
),
68+
WaterMark(
69+
watermark_word="random",
70+
watermark_font_size=(10, 15),
71+
watermark_font_thickness=(20, 25),
72+
watermark_font_type=cv2.FONT_HERSHEY_SIMPLEX,
73+
watermark_rotation=(0, 360),
74+
watermark_location="random",
75+
watermark_color="random",
76+
watermark_method="darken",
77+
p=0.33,
78+
),
3279
OneOf(
3380
[
3481
AugmentationSequence(
3582
[
36-
NoiseTexturize(),
37-
BrightnessTexturize(),
83+
NoiseTexturize(
84+
sigma_range=(3, 10),
85+
turbulence_range=(2, 5),
86+
),
87+
BrightnessTexturize(
88+
range=(0.9, 0.99),
89+
deviation=0.03,
90+
),
3891
],
3992
),
4093
AugmentationSequence(
4194
[
42-
BrightnessTexturize(),
43-
NoiseTexturize(),
95+
BrightnessTexturize(
96+
range=(0.9, 0.99),
97+
deviation=0.03,
98+
),
99+
NoiseTexturize(
100+
sigma_range=(3, 10),
101+
turbulence_range=(2, 5),
102+
),
44103
],
45104
),
46105
],
47-
p=0.5,
106+
p=0.33,
107+
),
108+
Brightness(
109+
range=(0.9, 1.1),
110+
min_brightness=0,
111+
min_brightness_value=(120, 150),
112+
p=0.1,
48113
),
49-
Brightness(p=0.5),
50114
]
51115

52116
post_phase = [
53-
OneOf([PageBorder(), DirtyRollers()], p=0.5),
54-
OneOf([LightingGradient(), Brightness()], p=0.5),
55-
DirtyDrum(p=0.5),
56-
SubtleNoise(p=0.5),
57-
Jpeg(p=0.5),
58-
Folding(p=0.5),
59-
Markup(p=0.5),
60-
PencilScribbles(p=0.5),
61-
OneOf([BookBinding(), BindingsAndFasteners()], p=0.5),
62-
BadPhotoCopy(p=0.5),
63-
Gamma(p=0.5),
64-
Geometric(p=0.5),
65-
Faxify(p=0.5),
117+
OneOf(
118+
[
119+
PageBorder(
120+
side="random",
121+
width_range=(5, 30),
122+
pages=None,
123+
noise_intensity_range=(0.3, 0.8),
124+
curve_frequency=(2, 8),
125+
curve_height=(2, 4),
126+
curve_length_one_side=(50, 100),
127+
value=(32, 150),
128+
),
129+
DirtyRollers(
130+
line_width_range=(2, 32),
131+
scanline_type=0,
132+
),
133+
],
134+
p=0.33,
135+
),
136+
OneOf(
137+
[
138+
LightingGradient(
139+
light_position=None,
140+
direction=None,
141+
max_brightness=255,
142+
min_brightness=0,
143+
mode="gaussian",
144+
linear_decay_rate=None,
145+
transparency=None,
146+
),
147+
Brightness(
148+
range=(0.9, 1.1),
149+
min_brightness=0,
150+
min_brightness_value=(120, 150),
151+
),
152+
],
153+
p=0.5,
154+
),
155+
DirtyDrum(
156+
line_width_range=(1, 6),
157+
line_concentration=random.uniform(0.05, 0.15),
158+
direction=random.randint(0, 2),
159+
noise_intensity=random.uniform(0.6, 0.95),
160+
noise_value=(64, 224),
161+
ksize=random.choice([(3, 3), (5, 5), (7, 7)]),
162+
sigmaX=0,
163+
p=0.33,
164+
),
165+
SubtleNoise(
166+
range=random.randint(5, 10),
167+
p=0.33,
168+
),
169+
Jpeg(
170+
quality_range=(25, 95),
171+
p=0.33,
172+
),
173+
Folding(
174+
fold_x=None,
175+
fold_deviation=(0, 0),
176+
fold_count=random.randint(1, 6),
177+
fold_noise=random.uniform(0, 0.2),
178+
gradient_width=(0.1, 0.2),
179+
gradient_height=(0.01, 0.02),
180+
p=0.33,
181+
),
182+
Markup(
183+
num_lines_range=(2, 7),
184+
markup_length_range=(0.5, 1),
185+
markup_thickness_range=(1, 2),
186+
markup_type=random.choice(["strikethrough", "crossed", "highlight", "underline"]),
187+
markup_color="random",
188+
single_word_mode=False,
189+
repetitions=1,
190+
p=0.33,
191+
),
192+
PencilScribbles(
193+
size_range=(100, 800),
194+
count_range=(1, 6),
195+
stroke_count_range=(1, 2),
196+
thickness_range=(2, 6),
197+
brightness_change=random.randint(64, 224),
198+
p=0.33,
199+
),
200+
OneOf(
201+
[
202+
BookBinding(
203+
radius_range=(1, 100),
204+
curve_intensity_range=(0, 70),
205+
mirror=0,
206+
mirror_range=(0.1, 0.2),
207+
),
208+
BindingsAndFasteners(
209+
overlay_types="darken",
210+
foreground=None,
211+
effect_type="random",
212+
ntimes=(2, 6),
213+
nscales=(0.9, 1.0),
214+
edge="random",
215+
edge_offset=(10, 50),
216+
use_figshare_library=0,
217+
),
218+
],
219+
p=0.33,
220+
),
221+
BadPhotoCopy(
222+
mask=None,
223+
noise_type=-1,
224+
noise_side="random",
225+
noise_iteration=(1, 2),
226+
noise_size=(1, 3),
227+
noise_value=(128, 196),
228+
noise_sparsity=(0.3, 0.6),
229+
noise_concentration=(0.1, 0.6),
230+
blur_noise=random.choice([True, False]),
231+
blur_noise_kernel=random.choice([(3, 3), (5, 5), (7, 7)]),
232+
wave_pattern=random.choice([True, False]),
233+
edge_effect=random.choice([True, False]),
234+
p=0.33,
235+
),
236+
Gamma(
237+
range=(0.9, 1.1),
238+
p=0.33,
239+
),
240+
Geometric(
241+
scale=(0.75, 1.25),
242+
translation=(-10, 10),
243+
fliplr=random.choice([True, False]),
244+
flipud=random.choice([True, False]),
245+
crop=(),
246+
rotate_range=(-5, 5),
247+
p=0.33,
248+
),
249+
Faxify(
250+
scale_range=(0.3, 0.6),
251+
monochrome=random.choice([0, 1]),
252+
monochrome_method="random",
253+
monochrome_arguments={},
254+
halftone=random.choice([0, 1]),
255+
invert=1,
256+
half_kernel_size=random.choice([(1, 1), (2, 2)]),
257+
angle=(0, 360),
258+
sigma=(1, 3),
259+
p=0.33,
260+
),
66261
]
67262

68263
pipeline = AugraphyPipeline(ink_phase, paper_phase, post_phase, log=False)
69264

70265
return pipeline
71266

72267

73-
def augment_using_default_pipeline(img):
268+
def default_augment(img):
74269

75270
default_pipeline = default_augraphy_pipeline()
76271

tests/default_pipeline_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def random_image():
1414

1515

1616
def test_default_pipeline(random_image):
17-
augmented = default_augraphy_pipeline(random_image)
17+
augmented = default_augment(random_image)["output"]

0 commit comments

Comments
 (0)