DirtyRollers#

class augraphy.augmentations.dirtyrollers.DirtyRollers(line_width_range=(8, 12), scanline_type=0, numba_jit=1, p=1)[source]#

Bases: Augmentation

Emulates an effect created by certain document scanners.

Parameters:

line_width_range – Pair of ints determining the range from which the

width of a dirty roller line is sampled. :type line_width_range: tuple, optional :param scanline_type: Types of scanline, use 0 for white background. :type scanline_type: int, optional :param numba_jit: The flag to enable numba jit to speed up the processing in the augmentation. :type numba_jit: int, optional :param p: The probability this Augmentation will be applied. :type p: float, optional

apply_scanline_mask(img, mask, meta_mask)[source]#

Main function to apply scanline mask to input image. :param img: The image to apply the function. :type img: numpy.array (numpy.uint8) :param mask: Mask of scanline effect. :type mask: numpy.array (numpy.uint8) :param meta_mask: Meta mask of scanline effect. :type meta_mask: numpy.array (numpy.uint8)

apply_scanline_mask_v1(img, mask, meta_mask)[source]#

Function to apply scanline mask to input image with white background. :param img: The image to apply the function. :type img: numpy.array (numpy.uint8) :param mask: Mask of scanline effect. :type mask: numpy.array (numpy.uint8) :param meta_mask: Meta mask of scanline effect. :type meta_mask: numpy.array (numpy.uint8)

apply_scanline_mask_v2(img, mask, meta_mask)[source]#

Function to apply scanline mask to input image with dark background. :param img: The image to apply the function. :type img: numpy.array (numpy.uint8) :param mask: Mask of scanline effect. :type mask: numpy.array (numpy.uint8) :param meta_mask: Meta mask of scanline effect. :type meta_mask: numpy.array (numpy.uint8)

apply_scanline_metamask_v1(img, mask)[source]#

Function to apply scanline meta mask to scanline mask of white background. :param img: The mask image to apply the function. :type img: numpy.array (numpy.uint8) :param mask: Meta mask of scanline effect. :type mask: numpy.array (numpy.uint8)

apply_scanline_metamask_v2(img, mask)[source]#

Function to apply scanline meta mask to scanline mask of dark background. :param img: The mask image to apply the function. :type img: numpy.array (numpy.uint8) :param mask: Meta mask of scanline effect. :type mask: numpy.array (numpy.uint8)

static create_scanline_mask(width, height, line_width)[source]#

Function to create scanline mask.

Parameters:
  • width (int) – Width of scanline mask.

  • height (int) – Height of scanline mask.

  • line_width (int) – Width of a dirty roller line.

Overview#

The Dirty Rollers augmentation emulates an effect created by certain document scanners.

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:

../../../_images/input.png

Example 1#

In this example, a DirtyRollers augmentation instance is initialized and the line width of dirty rollers effect is set to between 12 and 25 pixels (12,25). Scanline type is set to 0 (0) for white image background.

Code example:

dirty_rollers = DirtyRollers(line_width_range=(12, 25),
                            scanline_type=0,
                            )

img_dirty_rollers = dirty_rollers(image)
cv2.imshow("dirty_rollers", img_dirty_rollers)

Augmented image:

../../../_images/dirty_rollers.png