BleedThrough#

class augraphy.augmentations.bleedthrough.BleedThrough(intensity_range=(0.1, 0.9), color_range=(0, 224), ksize=(17, 17), sigmaX=1, alpha=0.2, offsets=(20, 20), p=1)[source]#

Bases: Augmentation

Emulates bleed through effect from the combination of ink bleed and gaussian blur operations.

Parameters:
  • intensity_range – Pair of floats determining the range from which noise intensity is sampled.

  • color_range (tuple, optional) – Pair of ints determining the range from which color noise is sampled.

  • ksize – Tuple of height/width pairs from which to sample the kernel size. Higher value increases the spreadness of bleeding effect.

  • sigmaX (float, optional) – Standard deviation of the kernel along the x-axis.

  • alpha (float, optional) – Intensity of bleeding effect, recommended value range from 0.1 to 0.5.

  • offsets (tuple, optional) – Tuple of x and y offset pair to shift the bleed through effect from original input.

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

blend(img, img_bleed, alpha)[source]#

Blend two images based on the alpha value to create bleedthrough effect.

Parameters:
  • img (numpy.array (numpy.uint8)) – The background image to apply the blending function.

  • img_bleed (numpy.array (numpy.uint8)) – The foreground image to apply the blending function.

  • alpha (float) – The alpha value of foreground image for the blending function.

create_bleedthrough_foreground(image: ndarray)[source]#

Create foreground image for bleedthrough effect.

Parameters:

image (numpy.array (numpy.uint8)) – The background image of the bleedthrough effect.

generate_bleeding_ink(img, intensity_range, color_range, ksize, sigmaX)[source]#

Preprocess and create bleeding ink effect in the input image.

Parameters:
  • img (numpy.array (numpy.uint8)) – The input image to apply the offset function.

  • intensity_range (tuple) – Pair of floats determining the range from which noise intensity is sampled.

  • color_range (tuple) – Pair of ints determining the range from which color noise is sampled.

  • ksize (tuple) – Tuple of height/width pairs from which to sample the kernel size. Higher value increases the spreadness of bleeding effect.

  • sigmaX (float) – Standard deviation of the kernel along the x-axis.

generate_offset(img_bleed, offsets)[source]#

Offset image based on the input offset value so that bleedthrough effect is visible and not stacked with background image.

Parameters:
  • img_bleed (numpy.array (numpy.uint8)) – The input image to apply the offset function.

  • offsets (int) – The offset value.

Overview#

The BleedThrough augmentation creates ink bleed through page effect from random image in cache folder or the reverse side of image if there’s no image in the cache directory.

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 BleedThrough augmentation instance is initialized. The bleeding intensity is set to moderate intensity range (0.1, 0.2). The bleed kernel size is set to large value (17, 17) to enable a larger bleeding effect. The alpha value is set to low value (0.3) so that the bleeding effect won’t be too distinct. The offsets value is set to random values between 10 and 20 (10,20) so that the bleeding ink effect will not stacked with the text in input image.

Code example:

bleedthrough = BleedThrough(intensity_range=(0.1, 0.2),
                            color_range=(0, 224),
                            ksize=(17, 17),
                            sigmaX=0,
                            alpha=0.3,
                            offsets=(10, 20),
                        )

img_bleedthrough = bleedthrough(image)
cv2.imshow("bleedthrough", img_bleedthrough)

Augmented image:

../../../_images/bleedthrough.png