DelaunayTessellation#

class augraphy.augmentations.delaunay.DelaunayTessellation(n_points_range=(500, 800), n_horizontal_points_range=(500, 800), n_vertical_points_range=(500, 800), noise_type='random', color_list='default', color_list_alternate='default', p=1)[source]#

Bases: Augmentation

The Delaunay Tessellation is a method of dividing a geometric space into a set of triangles. This implementation generate a Delaunay Tessellation of an image with Perlin Noise by default to create smoother, more organic looking tessellations. The Delaunay Tessellation algorithm is a method of traingulating a set of points in a planar space such that the minimum angle of each triangle is maximized. This ensures that the triangles are as close to equilateral as possible. The Delaunay Tessellation is defined as the triangulation of a set of points such that no point is inside the circumcircle of any triangle. The algorithm works by iteratively adding points to the triangulation and re-triangulating the set of points after each point is added. The algorithm ensures that the triangulation remains a Delaunay tessellation by checking for the Delaunay condition after each point is added. The Delaunay Condition states that the circumcircle of each triangle in the triangulation must contain no other points in its interior. The class inherits methods and properties from the Augmentation base class.

Parameters:
  • n_points_range (tuple (int), optional) – Range for the number of triangulating points from 500 to 800. Randomly selected.

  • n_horizontal_points_range (tuple (int), optional) – Range for the number of points in the horizontal edge, from 500 to 800. The value is randomly selected.

  • n_vertical_points_range (tuple (int), optional) – Range for the number of points in the vertical edge, from 500 to 800. The value is randomly selected.

  • noise_type (string, optional) – If “random”, integration of Perlin Noise in the pipeline is randomly selected. If noise_type is “perlin”, perlin noise is added to the background pattern, otherwise no Perlin Noise is added. Perlin Noise is added to the image to create a smoother, more organic looking tessellation.

  • color_list (list, optional) – A single list contains a collection of colors (in BGR) where the color of the effect will be randomly selected from it. Use “default” for default color or “random” for random colors.

  • color_list_alternate (list, optional) – A single list contains a collection of colors (in BGR) where the alternate color of the effect will be randomly selected from it. Use “default” for default color or “random” for random colors.

  • p (float, optional) – The probability of applying the augmentation to an input image. Default value is 1.0

apply_augmentation()[source]#

Overview#

The Delaunay augmentation applies Delaunay Tessellation with Perlin Noise by default, creating organic looking background patterns. Initially, a clean image with a 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 Delaunay Tessellation instance with Noise type is set to “random”, if the perlin is selected (randomly) from the algorithm, a background pattern is created and the patch is passed through the original image like a Sliding Window. The range of number of points on the geometric plane is set in between 500 and 800. The range of number of horizontal edge points is set between 50 and 100. The range of number of vertical points is set between 50 and 100.

Code example:

delaunay_pattern = DelaunayTessellation(
                                        n_points_range = (500, 800),
                                        n_horizontal_points_range=(50, 100),
                                        n_vertical_points_range=(50, 100),
                                        noise_type = "random")

img_final = delaunay_pattern(image)
cv2.imshow("Delaunay Image", img_final)

Augmented image:

../../../_images/delaunay.png

Delaunay Tessellation pattern_width = 480, pattern_height= 480, no. of random points on geometric plane = 502, no. of horizontal edge points = 65, no. of vertical edge points = 68, perlin_noise = True, window_size = 120

../../../_images/delaunay_1.png

Delaunay Tessellation pattern_width = 640, pattern_height= 640, no. of random points on geometric plane = 661, no. of horizontal edge points = 86, no. of vertical edge points = 73, perlin_noise = False, window_size = 160