Moire#

class augraphy.augmentations.moire.Moire(moire_density=(15, 20), moire_blend_method='normal', moire_blend_alpha=0.1, numba_jit=1, p=1)[source]#

Bases: Augmentation

Creates a moire pattern effect in the image by blending the moire pattern using OverlayBuilder.

Parameters:
  • moire_density (tuple, optional) – Pair of ints determining of density of the moire pattern stripes.

  • moire_blend_method (int, optional) – The blending method to blend moire pattern into the input image.

  • moire_blend_alpha (float, optional) – The blending alpha value for blending method with the usage of alpha.

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

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

blend_moire(image, image_moire)[source]#

Blend moire pattern into the image by using OverLayBuilder.

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

  • image_moire (numpy array, optional) – Image with generated moire pattern.

static generate_moire_pattern(xsize, ysize, density_range)[source]#

Generate moire pattern by using sine function.

Parameters:
  • xsize (int, optional) – Width of generated moire pattern.

  • ysize (int, optional) – Height of generated moire pattern.

  • density_range (tuple, optional) – Pair of ints determining of density of the moire pattern stripes.

Overview#

The Moire augmentation creates a moire pattern effect in the image by blending the moire pattern using OverlayBuilder.

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 Moire augmentation instance is initialized and the density of moire pattern is set to random value in between 15 and 20 (15,20). The method to blend moire pattern is set to “normal” method and the blending alpha is set to low value (0.1).

Code example:

moire = Moire(moire_density = (15,20),
              moire_blend_method = "normal",
              moire_blend_alpha = 0.1,
             )

img_moire = moire(image)
cv2.imshow("moire", img_moire)

Augmented image:

../../../_images/moire.png