DotMatrix#

class augraphy.augmentations.dotmatrix.DotMatrix(dot_matrix_shape='random', dot_matrix_dot_width_range=(3, 19), dot_matrix_dot_height_range=(3, 19), dot_matrix_min_width_range=(1, 2), dot_matrix_max_width_range=(150, 200), dot_matrix_min_height_range=(1, 2), dot_matrix_max_height_range=(150, 200), dot_matrix_min_area_range=(10, 20), dot_matrix_max_area_range=(2000, 5000), dot_matrix_median_kernel_value_range=(128, 255), dot_matrix_gaussian_kernel_value_range=(1, 3), dot_matrix_rotate_value_range=(0, 360), numba_jit=1, p=1)[source]#

Bases: Augmentation

Creates dot matrix effect by drawing dots of mean color in the detected contours.

Parameters:
  • dot_matrix_shape (string, optional) – The shape of single dot in dot matrix effect. The existing shapes are “cicle”, “rectangle”, “triangle” and “diamond”. Use “random” to select shape randomly.

  • dot_matrix_dot_width_range (tuple, optional) – Tuple of ints determining the width of single dot in dot matrix effect.

  • dot_matrix_dot_height_range (tuple, optional) – Tuple of ints determining the height of single dot in dot matrix effect.

  • dot_matrix_min_width_range (tuple, optional) – Pair of ints/floats determining the minimum width of the contour to apply the effect. If the value is within the range of 0.0 to 1.0 and the value is float, the minimum width will be scaled by image width: min width (int) = image width * min width (float and 0.0 - 1.0)

  • dot_matrix_max_width_range (tuple, optional) – Pair of ints/floats determining the maximum width of the contour to apply the effect. If the value is within the range of 0.0 to 1.0 and the value is float, the maximum width will be scaled by image width: max width (int) = image width * max width (float and 0.0 - 1.0)

  • dot_matrix_min_height_range (tuple, optional) – Pair of ints/floats determining the minimum height of the contour to apply the effect. If the value is within the range of 0.0 to 1.0 and the value is float, the minimum height will be scaled by image height: min height (int) = image height * min height (float and 0.0 - 1.0)

  • dot_matrix_max_height_range (tuple, optional) – Pair of ints/floats determining the maximum height of the contour to apply the effect. If the value is within the range of 0.0 to 1.0 and the value is float, the maximum height will be scaled by image height: max height (int) = image height * max height (float and 0.0 - 1.0)

  • dot_matrix_min_area_range (tuple, optional) – Pair of ints/floats determining the minimum area of the contour to apply the effect. If the value is within the range of 0.0 to 1.0 and the value is float, the minimum area will be scaled by image area: min area (int) = image area * min area (float and 0.0 - 1.0)

  • dot_matrix_max_area_range (tuple, optional) – Pair of ints/floats determining the maximum area of the contour to apply the effect. If the value is within the range of 0.0 to 1.0 and the value is float, the maximum area will be scaled by image area: max area (int) = image area * max area (float and 0.0 - 1.0)

  • dot_matrix_gaussian_kernel_value_range (tuple, optional) – Tuple of ints determining the Gaussian kernel value in blurring the dot matrix image.

  • dot_matrix_rotate_value_range (tuple, optional) – Tuple of ints determining the angle of rotation of the dot matrix effect.

  • numba_jit (int, optional) – The flag to enable numba jit to speed up the processing in the augmentation.

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

static fill_dot(image, image_dot_matrix, image_dot, image_mask, dot_matrix_dot_width, dot_matrix_dot_height, n_dot_x, n_dot_y, remainder_x, remainder_y)[source]#

The core function to fill output image with each dot image.

Parameters:
  • image (numpy array) – The input image.

  • image_dot_matrix (numpy array) – The output image.

  • image_dot (numpy array) – The image where it contains single dot of various shape.

  • image_mask (numpy array) – The mask to indicate the location to apply image dot into the output image.

  • dot_matrix_dot_width (int) – Width of single dot.

  • dot_matrix_dot_height (int) – Height of single dot.

  • n_dot_x (int) – The number of dots in horizontal direction.

  • n_dot_y (int) – The number of dots in vertical direction.

  • remainder_x (int) – The remaining horizontal pixels after all dots are applied.

  • remainder_y (int) – The remaining vertical pixels after all dots are applied.

Overview#

The DotMatrix augmentation creates dot matrix effect by drawing dots of mean color in the detected contours.

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 DotMatrix augmentation instance is initialized and the shape of dot matrix effect is set to circle (“circle”). The width and height of each dot in dot matrix effect is set to 5 pixels (5,5). The min and max width of the contours to apply the effect are 1 (1,1) and 50 (50,50) respectiely. The min and max height of the contours to apply the effect are 1 (1,1) and 50 (50,50) respectiely. The min and max area of the contours to apply the effect are 10 (10,10) and 800 (800,800) respectiely. The median kernel value in removing the existing contours is set to 29 (29,29). No Gaussian blurring is applied to the dot matrix effect (1,1). There is no rotation in each dot of the dot matrix effect too (0,0).

Code example:

dotmatrix = DotMatrix(dot_matrix_shape="circle",
                      dot_matrix_dot_width_range=(5, 5),
                      dot_matrix_dot_height_range=(5, 5),
                      dot_matrix_min_width_range=(1, 1),
                      dot_matrix_max_width_range=(50, 50),
                      dot_matrix_min_height_range=(1, 1),
                      dot_matrix_max_height_range=(50, 50),
                      dot_matrix_min_area_range=(10, 10),
                      dot_matrix_max_area_range=(800, 800),
                      dot_matrix_median_kernel_value_range = (29,29),
                      dot_matrix_gaussian_kernel_value_range=(1, 1),
                      dot_matrix_rotate_value_range=(0, 0)
                      )


img_dotmatrix = dotmatrix(image)
cv2.imshow("dotmatrix", img_dotmatrix)

Augmented image:

../../../_images/dot_matrix.png