InkColorSwap#

class augraphy.augmentations.inkcolorswap.InkColorSwap(ink_swap_color='random', ink_swap_sequence_number_range=(5, 10), ink_swap_min_width_range=(2, 3), ink_swap_max_width_range=(100, 120), ink_swap_min_height_range=(2, 3), ink_swap_max_height_range=(100, 120), ink_swap_min_area_range=(10, 20), ink_swap_max_area_range=(400, 500), p=1)[source]#

Bases: Augmentation

Swap color of ink in the image based on detected ink contours.

Parameters:
  • ink_swap_color (tuple, optional) – The swapping color (in BGR) of the effect.

  • ink_swap_sequence_number_range (tuple, optional) – Pair of ints determing the consecutive swapping number in the detected contours. Use “-1” to swap color for all detected contours.

  • ink_swap_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)

  • ink_swap_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)

  • ink_swap_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)

  • ink_swap_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)

  • ink_swap_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)

  • ink_swap_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)

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

Overview#

The InkColorSwap augmentation swaps color of ink in the image based on detected ink contours.

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 InkColorSwap augmentation instance is initialized and the swapping color is set to random (“random”). The continuous swapping count is set to random number in between 1 and 10 (1,10). The minimum contour width is set to 3 (3,3) and the maximum contour width is set to 100 (100,100). The minimum contour height is set to 3 (3,3) and the maximum contour height is set to 100 (100,100). The minimum contour area is set to 10 (10,10) and the maximum contour area is set to 400 (400,400).

Code example:

inkcolorswap= InkColorSwap(ink_swap_color = "random",
                           ink_swap_sequence_number_range = (1,10),
                           ink_swap_min_width_range=(3,3),
                           ink_swap_max_width_range=(100,100),
                           ink_swap_min_height_range=(3,3),
                           ink_swap_max_height_range=(100,100),
                           ink_swap_min_area_range=(10,10),
                           ink_swap_max_area_range=(400,400)
                           )

img_inkcolorswap = inkcolorswap(image)

cv2.imshow("inkcolorswap", img_inkcolorswap)

Augmented image:

../../../_images/ink_color_swap.png