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

Updated NoiseGenerator. #343

Merged
merged 1 commit into from
Aug 11, 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
13 changes: 5 additions & 8 deletions augraphy/augmentations/badphotocopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def apply_wave(self, mask, noise_side):
interpolation=cv2.INTER_AREA,
)
mask = 255 - cv2.multiply(img_wave, 255 - mask, scale=1 / 255)
# temporary, will be updated later for new noise side
else:
mask = 255 - cv2.multiply(img_wave, 255 - mask, scale=1 / 255)

return mask.astype("uint8")

Expand All @@ -222,7 +225,7 @@ def apply_augmentation(self, image):
ysize, xsize = image.shape[:2]

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

Expand Down Expand Up @@ -252,8 +255,6 @@ def apply_augmentation(self, image):

# rescale to 0 -255
mask = ((mask - np.min(mask)) / (np.max(mask) - np.min(mask))) * 255
if self.noise_value[0] > self.noise_value[1]:
self.noise_value[0] = self.noise_value[1]

# resize back to original size
mask = cv2.resize(mask, (xsize, ysize)).astype("uint8")
Expand All @@ -280,11 +281,7 @@ def apply_augmentation(self, image):
mask[mask > noise_mask] = 255
noise_img = mask

# add blur
gaussian_kernel = (random.choice([3, 5, 7]), random.choice([3, 5, 7]))
blurred = cv2.GaussianBlur(noise_img, gaussian_kernel, 0)
noise_img = cv2.multiply(noise_img, blurred, scale=1 / 255)

# blend noise into image
result = image.copy()
for i in range(3):
result[:, :, i] = cv2.multiply(noise_img, result[:, :, i], scale=1 / 255)
Expand Down
Loading
Loading