NoiseTexturize#
- class augraphy.augmentations.noisetexturize.NoiseTexturize(sigma_range=(3, 10), turbulence_range=(2, 5), texture_width_range=(100, 500), texture_height_range=(100, 500), p=1)[source]#
Bases:
Augmentation
Creates a random noise pattern to emulate paper textures. Consequently applies noise patterns to the original image from big to small.
- Parameters:
sigma_range (tuple, optional) – Defines bounds of noise fluctuations.
turbulence_range (tuple, optional) – Defines how quickly big patterns will be replaced with the small ones. The lower value - the more iterations will be performed during texture generation.
texture_width_range (tuple, optional) – Tuple of ints determining the width of the texture image. If the value is higher, the texture will be more refined.
texture_height_range (tuple, optional) – Tuple of ints determining the height of the texture. If the value is higher, the texture will be more refined.
p (float, optional) – The probability this Augmentation will be applied.
- noise(width, height, channel, ratio, sigma)[source]#
The function generates an image, filled with gaussian nose. If ratio parameter is specified, noise will be generated for a lesser image and then it will be upscaled to the original size. In that case noise will generate larger square patterns. To avoid multiple lines, the upscale uses interpolation.
- Parameters:
width (int) – Width of generated image.
height (int) – Height of generated image.
channel (int) – Channel number of generated image.
ratio (int) – The size of generated noise “pixels”.
sigma (int) – Defines bounds of noise fluctuations.
Overview#
The Noise Texturize augmentation creates a random noise pattern to emulate paper textures.
Initially, a clean image with single line of text is created.
Code example:
# import libraries
import cv2
import numpy as np
from augraphy import *
# create a clean image with single line of text
image = np.full((500, 1500,3), 250, dtype="uint8")
cv2.putText(
image,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit",
(80, 250),
cv2.FONT_HERSHEY_SIMPLEX,
1.5,
0,
3,
)
cv2.imshow("Input image", image)
Clean image:
Example 1#
In this example, a NoiseTexturize augmentation instance is initialized and the sigma value that define noise fluctuatiosn is set to random value in between 2 and 3 (2, 3). The noise turbulence range is set to random value in between 2 and 5 (2,5). The texture width and height are set to random value in netween 50 to 500 pixels (50, 500).
Code example:
noise_texturize = NoiseTexturize(sigma_range=(2, 3),
turbulence_range=(2, 5),
texture_width_range=(50, 500),
texture_height_range=(50, 500),
)
img_noise_texturize = noise_texturize(image)
cv2.imshow("noise_texturize", img_noise_texturize
Augmented image: