DirtyDrum#

class augraphy.augmentations.dirtydrum.DirtyDrum(line_width_range=(1, 4), line_concentration=0.1, direction=-1, noise_intensity=0.5, noise_value=(0, 30), ksize=(3, 3), sigmaX=0, p=1)[source]#

Bases: Augmentation

Emulates dirty drum effect by creating stripes of vertical and horizontal noises.

Parameters:
  • line_width_range (tuple, optional) – Pair of ints determining the range from which the width of a dirty drum line is sampled.

  • line_concentration (float, optional) – Concentration or number of dirty drum lines.

  • direction (int, optional) – Direction of effect, -1=random, 0=horizontal, 1=vertical, 2=both.

  • noise_intensity (float, optional) – Intensity of dirty drum effect, recommended value range from 0.8 to 1.0.

  • noise_value (tuple, optional) – Tuple of ints to determine value of dirty drum noise.

  • ksize – Tuple of height/width pairs from which to sample the kernel size. Higher value increases the spreadness of stripes.

  • sigmaX (float, optional) – Standard deviation of the kernel along the x-axis.

  • p (float, optional) – The probability this Augmentation will be applied.

add_noise(img, y0, yn, x0, xn)[source]#

Add noise to stripe of image.

Parameters:
  • img (numpy.array (numpy.uint8)) – The image to apply the function.

  • y0 (int) – The y start coordinate of the image stripe.

  • yn (int) – The y end coordinate of the image stripe.

  • x0 (int) – The x start coordinate of the image stripe.

  • xn (int) – The x end coordinate of the image stripe.

blend(img, img_dirty)[source]#

Blend two images to produce DirtyDrum effect。

Parameters:
  • img (numpy.array (numpy.uint8)) – The background image to apply the blending function.

  • img_dirty (numpy.array (numpy.uint8)) – The foreground image to apply the blending function.

create_dirty_mask(img, line_width_range=(6, 18), axis=1)[source]#

Create mask for drity drum effect。

Parameters:
  • img (numpy.array (numpy.uint8)) – The image to apply the function.

  • line_width_range (tuple) – Pair of ints determining the range from which the width of a dirty drum line is sampled.

  • axis (int) – The direction of noise line, 0 - horizontal, 1 - vertical.

Overview#

The Dirty Drum augmentation emulates deposits of dirt and ink-grime from dirty printer drums. It supports dirty drum effect in vertical, horizonal and both vertical and horizontal direction now.

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 DirtyDrum augmentation instance is initialized and the direction of dirty drum effect is set to horizontal (0). Each line width is set to between 1 to 4 pixels (1,4) and the line concentration is set to low value (0, 1). Noise intensity is set to moderate value (0.5) and the noise intensity value is set to between 0 and 30 (0, 30).

Code example:

dirtydrum1 = DirtyDrum(line_width_range=(1, 4),
                      line_concentration=0.1,
                      direction=0,
                      noise_intensity=0.5,
                      noise_value=(0, 30),
                      ksize=(3, 3),
                      sigmaX=0,
                      )

img_dirtydrum1 = dirtydrum1(image)
cv2.imshow("dirtydrum1", img_dirtydrum1)

Augmented image:

../../../_images/dirtydrum1.png

Example 2#

In this example, a DirtyDrum augmentation instance is initialized and the direction of dirty drum effect is set to vertical (1). Each line width is set to between 5 to 10 pixels (5,10) and the line concentration is set to low value (0.3). Noise intensity is set to low value (0.2) and the noise intensity value is set to between 0 and 10 (0, 10).

Code example:

dirtydrum2 = DirtyDrum(line_width_range=(5, 10),
                      line_concentration=0.3,
                      direction=1,
                      noise_intensity=0.2,
                      noise_value=(0, 10),
                      ksize=(3, 3),
                      sigmaX=0,
                      )

img_dirtydrum2 = dirtydrum2(image)
cv2.imshow("dirtydrum2", img_dirtydrum2)

Augmented image:

../../../_images/dirtydrum2.png

Example 3#

In this example, a DirtyDrum augmentation instance is initialized and the direction of dirty drum effect is set to both vertical and horizontal direction (2). Each line width is set to between 2 to 5 pixels (2,5) and the line concentration is set to low value (0.3). Noise intensity is set to moderate value (0.4) and the noise intensity value is set to between 0 and 5 (0, 5).

Code example:

dirtydrum3 = DirtyDrum(line_width_range=(2, 5),
                      line_concentration=0.3,
                      direction=2,
                      noise_intensity=0.4,
                      noise_value=(0, 5),
                      ksize=(3, 3),
                      sigmaX=0,
                      )

img_dirtydrum3 = dirtydrum3(image)
cv2.imshow("dirtydrum3", img_dirtydrum3)

Augmented image:

../../../_images/dirtydrum3.png