InkShifter#
- class augraphy.augmentations.inkshifter.InkShifter(text_shift_scale_range=(18, 27), text_shift_factor_range=(1, 4), text_fade_range=(0, 2), blur_kernel_size=(5, 5), blur_sigma=0, noise_type='random', p=1.0)[source]#
Bases:
Augmentation
- displace_image(img, mask, mapx, mapy, fill=(255, 255, 255))[source]#
Apply displacement map to an image.
- Parameters:
img (numpy array) – Input Image
mask (numpy array (uint8)) – The mask of labels for each pixel. Mask value should be in range of 1 to 255. Value of 0 will be assigned to the filled area after the transformation.
mapx (numpy array) – x-componet of the displacement map
mapy (numpy array) – y component of the displacement map
fill (tuple) – Fill value of the pixels outside the image in BGR
- noise_map(shape, res=(64, 64))[source]#
Generate a noise map based on Perlin Noise
- Parameters:
shape (tuple) – Desired shape of the perlin noise map
res (tuple, optional) – Resolution of the noise map
- noise_map_fractal(shape, res=(64, 64), octaves=1, persistence=0.5)[source]#
Generate a fractal noise map
- Parameters:
shape (tuple) – desired shape of the fractal noise map
res (tuple, optional) – resolution of the noise map
octaves (int, optional) – Number of octaves in the fractal noise
persistence (float, optional) – Persistence value for the fractal nois
Overview#
The Inkshifter Augmentation applies a noise map on the image and displaces the text on the image. For additional input such as mask, keypoints and bounding boxes, only mask is supported.
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, we demonstrate the usage of the InkShifter augmentation. This augmentation specializes in producing the “text jittering” effect by introducing various noise patterns. By default, the augmentation employs the “random” noise type, offering a diverse selection of noise options. The text shift scale range is typically set between 18 and 27, determining the magnitude of the shifting effect. Additionally, the text shift factor range specifies the range of factors by which the text can be shifted, typically varying from 1 to 4. The text fade range, by default, spans from 0 to 2, allowing for fading effects. The InkShifter augmentation provides two noise functions for image pixel distortion: Perlin Noise and Fractal Noise. Perlin Noise, offering image distortion through a Perlin Noise Map, is the default option for producing the desired effect. By following the documentation, users can effectively utilize the InkShifter augmentation to introduce text jittering effects with customizable noise options and parameters.
By modifying the text_shift_scale_range and text_shift_factor_range parameters, we can control the level of text distortion in the augmentation. Adjusting the text_shift_scale_range allows us to change the extent of the text’s left and right movement, while modifying the text_shift_factor_range enables us to manipulate the text’s vertical and horizontal displacement. In this way, we have the flexibility to customize the amount and direction of the text’s movement according to our desired effect.
Inspiration Repository : sherlockdoyle/Handwriter
Code example:
inkshifter_obj = InkShifter(
text_shift_scale_range=(18, 27),
text_shift_factor_range=(1, 4),
text_fade_range=(0, 2),
noise_type = "random",
)
inkshifter_img = inkshifter_obj(image)
cv2.imshow("Inkshifter Augmentation", inkshifter_img)
Augmented image1:
Augmented image2:
Example 2#
In this example, we demonstrate the usage of the InkShifter augmentation in image and an additional mask input. The InkShifter augmentation will be using the default parameters value and hence no additional parameters value will be specified.
Code example:
inkshifter_obj = InkShifter()
inkshifter_img, mask, _, _ = inkshifter_obj(image=image, mask=mask)
cv2.imshow("Inkshifter Augmentation", inkshifter_img)
Input mask:
Augmented image:
Augmented mask: