VoronoiTessellation#

class augraphy.augmentations.voronoi.VoronoiTessellation(mult_range=(50, 80), seed=19829813472, num_cells_range=(500, 1000), noise_type='random', background_value=(200, 255), numba_jit=1, p=1)[source]#

Bases: Augmentation

This script generates a Voronoi Tessellation based on a set of random points in a plane. The tessellation is visualized by coloring or shading the region around each point with the color or shade of the corresponding random point. By default, Perlin Noise is added to the distances between each point and its closest random point to create a smoother, more organic looking tessellation. The class inherits methods and properties from the Augmentation base class.

Parameters:
  • mult_range (tuple (int), optional) – range for amplification factor to generate Perlin noise , default lies between 50 and 80

  • seed (int, optional) – The seed value for generating the Perlin Noise, default value is 19829813472

  • num_cells_range (tuple (int), optional) – Range for the number of cells used to generate the Voronoi Tessellation. Default lies between 1000 and 9000.

  • 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.

  • background_value (tuple (int)) – Range for background color assigned to each point

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

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

apply_augmentation()[source]#
static generate_voronoi(width, height, num_cells, nsize, pixel_data, perlin_noise_2d)[source]#

Generates Voronoi Tessellation

Overview#

The Voronoi augmentation applies Voronoi 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 VoronoiTessellation 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 pattern background value for each randomly selected point is set to bright value (250, 256). The number of random points generated is set in between 500 and 800. Amplification factor for Perlin Noise is set in between 50 and 80 and the seed is set to 19829813472.

Code example:

voronoi_pattern = VoronoiTessellation(
                         mult_range = (50,80),
                         seed = 19829813472 ,
                         num_cells_range = (500,800),
                         noise_type = "random",
                         background_value = (200, 256)
                        )

img_voronoi = voronoi_pattern(image)
cv2.imshow("Voronoi Pattern", img_voronoi)

Augmented image:

../../../_images/voronoi.png
../../../_images/voronoi_1.png

Voronoi Tessellation: width = 140. height = 140, amplification_factor_range = 64 , seed = 19829813472, number of random points = 1975, perlin=True, background_value = (200, 256), window_size=70

../../../_images/voronoi_2.png

Voronoi Tessellation: width = 200. height = 200, amplification_factor_range = 63 , seed = 19829813472, number of random points = 733, perlin=False, background_value = (200, 256), window_size=200