LowInkRandomLines#

class augraphy.augmentations.lowinkrandomlines.LowInkRandomLines(count_range=(5, 10), use_consistent_lines=True, noise_probability=0.1, p=1)[source]#

Bases: LowInkLine

Adds low ink lines randomly throughout the image.

Parameters:
  • count_range (tuple, optional) – Pair of ints determining the range from which the number of lines is sampled.

  • use_consistent_lines (bool, optional) – Whether or not to vary the width and alpha of generated low ink lines.

  • noise_probability (float, optional) – The probability to add noise into the generated lines.

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

Overview#

LowInkRandomLines inherits from LowInkLine. LowInkRandomLines adds low ink lines randomly throughout the image.

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 LowInkPeriodicLines augmentation instance is initialized and lines count is set to random value in between 30 and 50 (30, 50). It is set to use consistent lines (True) and the noise probability is set to low value (0.1).

Code example:

low_ink_random_line_consistent =  LowInkRandomLines(count_range=(30, 50),
                                                    use_consistent_lines=True,
                                                    noise_probability=0.1,
                                                    )

img_low_ink_random_line_consistent = low_ink_random_line_consistent(image)
cv2.imshow("low_ink_random_line_consistent", img_low_ink_random_line_consistent)

Augmented image:

../../../_images/low_ink_random_line_consistent.png

Example 2#

In this example, a LowInkPeriodicLines augmentation instance is initialized and lines count is set to random value in between 30 and 50 (30, 50). It is set to use non-consistent lines (False) and the noise probability is set to low value (0.1).

Code example:

low_ink_random_line_non_consistent =  LowInkRandomLines(count_range=(30, 50),
                                                        use_consistent_lines=False,
                                                        noise_probability=0.1,
                                                        )

img_low_ink_random_line_non_consistent = low_ink_random_line_non_consistent(image)
cv2.imshow("low_ink_random_line_non_consistent", img_low_ink_random_line_non_consistent)

Augmented image:

../../../_images/low_ink_random_line_non_consistent.png