ColorShift#

class augraphy.augmentations.colorshift.ColorShift(color_shift_offset_x_range=(3, 5), color_shift_offset_y_range=(3, 5), color_shift_iterations=(2, 3), color_shift_brightness_range=(0.9, 1.1), color_shift_gaussian_kernel_range=(3, 3), p=1)[source]#

Bases: Augmentation

Shifts each BGR color channel by certain offsets to create a shifted color effect.

Parameters:
  • color_shift_offset_x_range (tuple, optional) – Pair of ints/floats determining the value of x offset in shifting each color channel. If the value is within the range of 0.0 to 1.0 and the value is float, the x offset will be scaled by image width: x offset (int) = image width * x offset (float and 0.0 - 1.0)

  • color_shift_offset_y_range (tuple, optional) – Pair of ints/floats determining the value of y offset in shifting each color channel. If the value is within the range of 0.0 to 1.0 and the value is float, the y offset will be scaled by image height: y offset (int) = image height * y offset (float and 0.0 - 1.0)

  • color_shift_iterations (tuple, optional) – Pair of ints determining the number of iterations in applying the color shift operation.

  • color_shift_brightness_range (tuple, optional) – Pair of floats determining the brightness value of the shifted color channel. The optimal brightness range is 0.9 to 1.1.

:param color_shift_gaussian_kernel_range : Pair of ints determining the Gaussian kernel value in blurring the shifted image. :type color_shift_gaussian_kernel_range : tuple, optional :param p: The probability that this Augmentation will be applied. :type p: float, optional

apply_color_shift(image, kernel_value)[source]#

Main function to apply color shift process.

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

  • kernel_value (int) – The Gaussian kernel value for the blurring effect.

Overview#

The ColorShift augmentation shifts each color channel by certain offsets to create a shifted color effect.

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 ColorShift augmentation instance is initialized and the shifting offset in both horizontal and vertical direction is set to random value in between 3 and 5 (3,5). The number of color shift iterations is set randomly to 2 or 3 times (2,3). The brightness range of the shifted color channel is set to any random value between 0.9 and 1.1 (0.9, 1.1). The Gaussian kernel value in blurring the shifted color channel is set to 3 (3,3).

The saturation changes range is set to low value (10,30).

Code example:

colorshift = ColorShift(color_shift_offset_x_range = (3,5),
                        color_shift_offset_y_range = (3,5),
                        color_shift_iterations = (2,3),
                        color_shift_brightness_range = (0.9,1.1),
                        color_shift_gaussian_kernel_range = (3,3),
                        )

img_colorshift = colorshift(image)
cv2.imshow("colorshift", img_colorshift)

Augmented image:

../../../_images/color_shift.png