Hollow#

class augraphy.augmentations.hollow.Hollow(hollow_median_kernel_value_range=(71, 101), hollow_min_width_range=(1, 2), hollow_max_width_range=(150, 200), hollow_min_height_range=(1, 2), hollow_max_height_range=(150, 200), hollow_min_area_range=(10, 20), hollow_max_area_range=(2000, 5000), hollow_dilation_kernel_size_range=(1, 2), p=1)[source]#

Bases: Augmentation

Creates hollow effect by replacing detected contours with edges.

The detected contours are removed by using median filter operation.

Parameters:
  • hollow_median_kernel_value_range (tuple, optional) – Pair of ints determining the median filter kernel value.

  • hollow_min_width_range (tuple, optional) – Pair of ints/floats determining the minimum width of the contour. 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)

  • hollow_max_width_range (tuple, optional) – Pair of ints/floats determining the maximum width of the contour. 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)

  • hollow_min_height_range (tuple, optional) – Pair of ints/floats determining the minimum height of the contour. 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)

  • hollow_max_height_range (tuple, optional) – Pair of ints/floats determining the maximum height of the contour. 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)

  • hollow_min_area_range (tuple, optional) – Pair of ints/floats determining the minimum area of the contour. 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)

  • hollow_max_area_range (tuple, optional) – Pair of ints/floats determining the maximum area of the contour. 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)

  • hollow_dilation_kernel_size_range (tuple, optional) – Pair of ints determining the kernel value of the dilation. The dilation affect the final thickness of the hollow efect.

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

Overview#

The Hollow augmentation creates hollow effect by replacing detected contours with edges. The detected contours are removed by using median filter operation.

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 Hollow augmentation instance is initialized. The median kernel value is set to 101 (101,101) so that it can remove moderate size contours. The min and max width of the contours are 1 (1,1) and 200 (200,200) respectiely. The min and max height of the contours are 1 (1,1) and 200 (200,200) respectiely. The min and max area of the contours are 10 (10,10) and 5000 (5000,5000) respectiely. The dilation kernel value is 3 (3,3) so tha thickhen the generated hollow effect.

Code example:

hollow = Hollow(hollow_median_kernel_value_range = (101, 101),
                hollow_min_width_range=(1, 1),
                hollow_max_width_range=(200, 200),
                hollow_min_height_range=(1, 1),
                hollow_max_height_range=(200, 200),
                hollow_min_area_range=(10, 10),
                hollow_max_area_range=(5000, 5000),
                hollow_dilation_kernel_size_range = (3, 3),
                )

img_hollow= hollow(image)
cv2.imshow("hollow", img_hollow)

Augmented image:

../../../_images/hollow.png