Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit e1409e3

Browse files
authored
Merge pull request #22 from kwcckw/dev
Updates in probability.
2 parents 2b38f06 + 96b6e29 commit e1409e3

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

shabbypipeline.py

+34-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def get_pipeline():
1616
dithering_dither_type = random.choice(["ordered", "floyd-steinberg"])
1717
# Dithering.order determines the dimensions of the threshold map
1818
dithering_order = random.choice(range(3,10))
19+
# dithering.p is the probability to run this augmentation
20+
dithering_p = (random.random()>0.7) * 1
1921

2022
# InkBleed.intensity_range is a tuple with bounds for bleed intensity to be selected from
2123
inkbleed_intensity_range = (0.1, 0.4)
@@ -51,6 +53,8 @@ def get_pipeline():
5153
letterpress_value_threshold_range=(96, 128)
5254
# Letterpress.blur enables blur in the noise mask
5355
letterpress_blur=1
56+
# Letterpress.p is the probability to run this augmentation
57+
letterpress_p = (random.random()>0.5) * 1
5458

5559
# LowInkLines.count_range is a pair determining how many lines should be drawn
5660
lowinkrandomlines_count_range = (3, 12)
@@ -98,7 +102,9 @@ def get_pipeline():
98102
dirtyrollers_line_width_range = (2, 32)
99103
# DirtyRollers.scanline_type changes the background of lines
100104
dirtyrollers_scanline_type = 0
101-
105+
# DirtyRollers.p is the probability to run this augmentation
106+
dirtyrollers_p = (random.random()>0.5) * 1
107+
102108
# LightingGradient.mask_size determines how big the mask should be
103109
lightinggradient_light_position = None
104110
# LightingGradient.direction indicates the rotation degree of the light strip
@@ -127,7 +133,9 @@ def get_pipeline():
127133
dirtydrum_ksize = random.choice([(3, 3),(5,5),(7,7)])
128134
# DirtyDrum.sigmaX is the stdev of the kernel in the x direction
129135
dirtydrum_sigmaX = 0
130-
136+
# DirtyDrum.p is the probability to run this augmentation
137+
dirtydrum_p = (random.random()>0.5) * 1
138+
131139
# SubleNoise.range gives the variation range for sampling noise
132140
subtlenoise_range = 10
133141

@@ -150,6 +158,8 @@ def get_pipeline():
150158
markup_single_word_mode=random.choice([True, False])
151159
# Markup.repetitions determines the number of times the effect is drawn
152160
markup_repetitions=random.randint(1,2) if markup_type == "highlight" else 1
161+
# Markup.p is the probability to run this augmentation
162+
markup_p = (random.random()>0.5) * 1
153163

154164
# PencilScribbles.size_range determines the size of scribbles to draw
155165
pencilscribbles_size_range=(100, 700)
@@ -161,7 +171,9 @@ def get_pipeline():
161171
pencilscribbles_thickness_range=(2, 6)
162172
# PencilScribbles.brightness_change is the brightness value of each stroke
163173
pencilscribbles_brightness_change=random.randint(64,224)
164-
174+
# PencilScribbles.p is the probability to run this augmentation
175+
pencilscribbles_p = (random.random()>0.5) * 1
176+
165177
# BindingsAndFasteners.overlay_types can be min, max, or mix
166178
bindingsandfasteners_overlay_types = "darken"
167179
# BindingsAndFasteners.foreground is the path to fg image or the image itself
@@ -201,6 +213,8 @@ def get_pipeline():
201213
badphotocopy_wave_pattern=random.choice([True,False])
202214
# BadPhotoCopy.edge_effect adds the Sobel edge effect to the noise mask
203215
badphotocopy_edge_effect=random.choice([True,False])
216+
# BadPhotoCopy.p is the probability to run this augmentation
217+
badphotocopy_p = (random.random()>0.5) * 1
204218

205219
# Gamma.range is an interval from which to sample a gamma shift
206220
gamma_range = (0.8, 1.2)
@@ -237,6 +251,14 @@ def get_pipeline():
237251
# Faxify.sigma is the sigma value of the Gaussian kernel in the halftone effect
238252
faxify_sigma=(1,3)
239253

254+
# to prevent text becomes unreadable after the agumentation
255+
if badphotocopy_p>0 or dirtyrollers_p>0 or dirtydrum_p>0 or markup_p>0 or pencilscribbles_p>0:
256+
faxify_monochrome_method = "grayscale"
257+
if dithering_p or faxify_halftone:
258+
letterpress_p = 0
259+
if dithering_p:
260+
faxify_halftone = 0
261+
240262
################################################################################
241263
# PIPELINE
242264
#
@@ -246,13 +268,13 @@ def get_pipeline():
246268
ink_phase = [
247269
Dithering(dithering_dither_type,
248270
dithering_order,
249-
p=0.2),
271+
p=dithering_p),
250272

251273
InkBleed(inkbleed_intensity_range,
252274
inkbleed_color_range,
253275
inkbleed_kernel_size,
254276
inkbleed_severity,
255-
p=1),
277+
p=0.5),
256278

257279
BleedThrough(bleedthrough_intensity_range,
258280
bleedthrough_color_range,
@@ -268,7 +290,7 @@ def get_pipeline():
268290
letterpress_value_range,
269291
letterpress_value_threshold_range,
270292
letterpress_blur,
271-
p=0.5),
293+
p=letterpress_p),
272294

273295
OneOf(
274296
[
@@ -329,7 +351,8 @@ def get_pipeline():
329351
pageborder_value),
330352

331353
DirtyRollers(dirtyrollers_line_width_range,
332-
dirtyrollers_scanline_type)
354+
dirtyrollers_scanline_type,
355+
p=dirtyrollers_p)
333356
],
334357
p=0.5),
335358

@@ -354,7 +377,7 @@ def get_pipeline():
354377
dirtydrum_noise_value,
355378
dirtydrum_ksize,
356379
dirtydrum_sigmaX,
357-
p=0.5),
380+
p=dirtydrum_p),
358381

359382
SubtleNoise(subtlenoise_range,
360383
p=0.5),
@@ -369,14 +392,14 @@ def get_pipeline():
369392
markup_color,
370393
markup_single_word_mode,
371394
markup_repetitions,
372-
p=0.5),
395+
p=markup_p),
373396

374397
PencilScribbles(pencilscribbles_size_range,
375398
pencilscribbles_count_range,
376399
pencilscribbles_stroke_count_range,
377400
pencilscribbles_thickness_range,
378401
pencilscribbles_brightness_change,
379-
p=0.5),
402+
p=pencilscribbles_p),
380403

381404
BindingsAndFasteners(bindingsandfasteners_overlay_types,
382405
bindingsandfasteners_foreground,
@@ -399,7 +422,7 @@ def get_pipeline():
399422
badphotocopy_blur_noise_kernel,
400423
badphotocopy_wave_pattern,
401424
badphotocopy_edge_effect,
402-
p=0.5),
425+
p=badphotocopy_p),
403426

404427
Gamma(gamma_range,
405428
p=0.5),

0 commit comments

Comments
 (0)