PatternGenerator#
- class augraphy.augmentations.quasicrystal.PatternGenerator(imgx=512, imgy=512, n_rotation_range=(10, 15), color='random', alpha_range=(0.25, 0.5), numba_jit=1, p=1.0)[source]#
Bases:
Augmentation
In this implementation we take a geometric plane and every point in the plane is shaded according to its position,(x,y) coordinate. We take the pattern and perform a bitwise not operation so that it can be added as an background to an image.This code is a python implementation of a QuasiPattern Distortion augmentation techniques using PIL and the OpenCV libraries. This augmentation creates a new pattern image and superimposes it onto an input image. To make the pattern more prominent a. Increase the ‘frequency’ parameter: Increasing the frequency of the pattern will the it tightly populated and more prominent. b. Decrease the ‘n_rotation’ parameter: Decreasing the number of rotations will make the pattern less symmetrical.
- Parameters:
imgx (int, optional) – width of the pattern image. default is 512
imgy (int, optional) – height of the pattern image, default is 512
n_rotation (tuple (int) , optional) – is the number of rotations applied to the pattern, default value lies between 10 and 15.
color (tuple (int), optional) – Color of the pattern in BGR format. Use “random” for random color effect.
alpha_range (tuple (float), optional) – Tuple of floats determining the alpha value of the patterns.
numba_jit (int, optional :param p: The probability this Augmentation will be applied.) – The flag to enable numba jit to speed up the processing in the augmentation.
Overview#
The PatternGenerator creates aperiodic crystals. We take a geometric plane and each point on the geometric plane is transformed to a cosine function with phase and amplitude.
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 PatternGenerator instance with number of rotation is set between 10 and 15. The background image size is set of width = 512 and height = 512.
Code example:
quasi_pattern = PatternGenerator(
imgx = 512,
imgy= 512,
n_rotation_range = (10,15)
)
img_final = quasi_pattern(image)
cv2.imshow("Image", img_final)
Augmented image: