Scribbles#

class augraphy.augmentations.scribbles.Scribbles(scribbles_type='random', scribbles_ink='random', scribbles_location='random', scribbles_size_range=(400, 600), scribbles_count_range=(1, 6), scribbles_thickness_range=(1, 3), scribbles_brightness_change=[32, 64, 128], scribbles_skeletonize=0, scribbles_skeletonize_iterations=(2, 3), scribbles_color='random', scribbles_text='random', scribbles_text_font='random', scribbles_text_rotate_range=(0, 360), scribbles_lines_stroke_count_range=(1, 6), p=1)[source]#

Bases: Augmentation

Applies scribbles to image.

Parameters:
  • scribbles_type (string, optional) – Types of scribbles, choose from “random”, “lines” or “text”.

  • scribbles_ink (string, optional) – Types of scribbles ink, choose from “random”, “pencil”, “pen” or “marker”.

  • scribbles_location (tuple or string, optional) – Tuple of ints or floats (x,y) determining location of scribbles effect or use “random” for random location. The value will be in percentage of the image size if the value is float and in between 0 - 1: x (int) = image width * x (float and 0 - 1); y (int) = image height * y (float and 0 - 1)

  • scribbles_size_range (tuple, optional) – Pair of floats determining the range for the size of the scribble to be created.

  • scribbles_count_range (tuple, optional) – Pair of floats determining the range for the number of scribbles to create.

  • scribbles_thickness_range (tuple, optional) – Pair of floats determining the range for the size of the scribbles to create.

  • scribbles_brightness_change (list, optional) – A list of value change for the brightness of the strokes. Default 128 creates a graphite-like appearance. 32 creates a charcoal-like appearance. If more than one value is provided, the final value will be randomly selected.

  • scribbles_skeletonize (int, optional) – Flag to enable skeletonization effect.

  • scribbles_skeletonize_iterations (tuple, optional) – Tuple of ints determing number of skeletonization iterations.

  • scribbles_color (tuple, optional) – Tuple of ints (BGR) determining the color of scribbles, or use “random” for random color.

  • scribbles_text (string, optional) – Text value for “text” based scribbles.

  • scribbles_text_font (string, optional) – Font types for “text” based scribbles. It can be the path to the ttf file, a path to the folder contains ttf files, an url to the ttf file, or simply “random” to use default randomized font types.

  • scribbles_text_rotate_range (tuple, optional) – Tuple of ints to determine rotation angle of “text” based scribbles.

  • scribbles_lines_stroke_count_range (tuple, optional) – Pair of floats determining the range for the number of strokes to create in each scribble.

  • p (float, optional) – Probability of this Augmentation being applied.

Overview#

The Scribbles augmentation applies random scribbles to 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 Scribbles augmentation instance is initialized and the scribbles type is set to “random”, where it selects “lines” or “text” based scribbles randomly. The scribbles_ink is set to “random”, where it selects “pencil”, “pen”, “marker” or “highlighter” randomly. The location of scribbles is “random” and the size of scribbles effect is set in between 400 to 600 pixels (400, 600). Number of scribbles is set in between 1 to 6 (1,6) and the thickness of scribbles is set to random value in between 1 and 3 (1,3). The brightness change of scribbles effect is set to select randomly from 8 and 16 [8, 16]. The color of scribbles is set to “random”. If the scribbles type is “text”, the scribbles text value and font type is set to “random” where it selects randomly from the internal settings. Additionally, the scribbles text rotate range is set to rotate randomly in any angle between 0 to 360 degree (0, 360). If the scribbles type is “lines”, the stroke count for each scribbles is set at random value in between 1 and 6 (1, 6).

Code example:

scribbles = Scribbles(scribbles_type="random",
                      scribbles_ink="random",
                      scribbles_location="random",
                      scribbles_size_range=(400, 600),
                      scribbles_count_range=(1, 6),
                      scribbles_thickness_range=(1, 3),
                      scribbles_brightness_change=[8, 16],
                      scribbles_skeletonize=0,
                      scribbles_skeletonize_iterations=(2, 3),
                      scribbles_color="random",
                      scribbles_text="random",
                      scribbles_text_font="random",
                      scribbles_text_rotate_range=(0, 360),
                      scribbles_lines_stroke_count_range=(1, 6),
                      )

img_scribbles = scribbles(image)
cv2.imshow("scribbles", img_scribbles)

Augmented image:

../../../_images/scribbles.png