Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully updated NoiseGenerator and BadPhotoCopy. #344

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions augraphy/augmentations/badphotocopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ class BadPhotoCopy(Augmentation):
:param mask: Mask of noise to generate badphotocopy effect.
:type mask: uint8, optional
:param noise_type: Types of noises to generate different mask patterns. Use -1 to select randomly.
1 = default, even spread of noise
2 = noise with regular pattern
3 = noise at all borders of image
4 = sparse and little noise
5 = gaussian noise
6 = perlin noise
7 = worley noise
1 = sklearn.datasets' make_blobs noise
2 = gaussian noise
3 = perlin noise
4 = worley noise
5 = rectangular pattern noise
:type noise_type: int, optional
:param noise_side: Location of noise.
:param noise_side: Location of noise. Select from:
"random", "left", "top", "right", "bottom", "top_left", "top_right", "bottom_left", "bottom_right", "none", "all".
:type noise_side: string, optional
:param noise_iteration: Pair of ints to determine number of iterations to apply noise in the mask.
:type noise_iteration: tuple, optional
Expand Down Expand Up @@ -225,7 +224,20 @@ def apply_augmentation(self, image):
ysize, xsize = image.shape[:2]

if self.noise_side == "random":
noise_side = random.choice(["left", "top", "right", "bottom", "none", "all"])
noise_side = random.choice(
[
"left",
"top",
"right",
"bottom",
"top_left",
"top_right",
"bottom_left",
"bottom_right",
"none",
"all",
],
)
else:
noise_side = self.noise_side

Expand Down Expand Up @@ -253,9 +265,6 @@ def apply_augmentation(self, image):
ysize=ysize,
)

# rescale to 0 -255
mask = ((mask - np.min(mask)) / (np.max(mask) - np.min(mask))) * 255

# resize back to original size
mask = cv2.resize(mask, (xsize, ysize)).astype("uint8")

Expand All @@ -277,7 +286,7 @@ def apply_augmentation(self, image):

# add dotted noise effect to mask (unsmoothen)
if not blur_noise:
noise_mask = np.random.random((ysize, xsize)) * 225
noise_mask = np.random.randint(0, 255, (ysize, xsize))
mask[mask > noise_mask] = 255
noise_img = mask

Expand Down
Loading
Loading