LightingGradient#

class augraphy.augmentations.lightinggradient.LightingGradient(light_position=None, direction=None, max_brightness=255, min_brightness=0, mode='gaussian', linear_decay_rate=None, transparency=None, numba_jit=1, p=1)[source]#

Bases: Augmentation

Generates a decayed light mask generated by light strip given its position and direction, and applies it to the image as a lighting or brightness gradient.

Parameters:
  • position (tuple, optional) – Tuple of ints (x, y) defining the center of light strip position, which is the reference point during rotation.

  • direction (int, optional) – Integer from 0 to 360 to indicate the rotation degree of light strip.

  • max_brightness (int, optional) – Integer that max brightness in the mask.

  • min_brightness (int, optional) – Integer that min brightness in the mask

  • mode (string, optional) – The way that brightness decay from max to min: linear or gaussian

  • linear_decay_rate (float, optional) – Only valid in linear_static mode. Suggested value is within [0.2, 2].

  • transparency (float, optional) – Transparency of input image.

  • 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.

static apply_decay_value_linear(mask, canvas_y, max_value, padding_center, decay_rate)[source]#

Decay from max to min value with static linear decay rate.

Parameters:
  • mask (numpy.array) – Output image

  • canvas_y (int) – Lighting image canvas max size.

  • max_value (int) – Max of decayed value.

  • padding_center (int) – Center padding position.

  • decay_rate (float) – Rate of linear decay.

static apply_decay_value_norm(mask, canvas_y, max_value, min_value, center, grange)[source]#

Decay from max to min value following Gaussian distribution

Parameters:
  • mask (numpy.array) – Output image

  • canvas_y (int) – Lighting image canvas max size.

  • max_value (int) – Max of decayed value.

  • min_value (int) – Min of decayed value.

  • center (int) – Center of decayed value

  • grange (int) – Range of decay.

generate_parallel_light_mask(mask_size, position=None, direction=None, max_brightness=255, min_brightness=0, mode='gaussian', linear_decay_rate=None)[source]#

Generates mask of parallel light.

Parameters:
  • mask_size (tuple) – Tuple of ints (w, h) defining generated mask size

  • position (tuple) – Tuple of ints (x, y) defining the center of light strip position, which is the reference point during rotation.

  • direction (int) – Integer from 0 to 360 to indicate the rotation egree of light strip.

  • max_brightness (int) – Integer that max brightness in the mask.

  • min_brightness (int) – Integer that min brightness in the mask

  • mode (string) – The way that brightness decay from max to min: linear or gaussian.

  • linear_decay_rate (float) – Only valid in linear_static mode. Suggested value is within [0.2, 2].

Overview#

The Lighting Gradient augmentation produces a decayed light mask generated by a light strip given position and direction, and applies it to the image as a lighting or brightness gradient.

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 LightingGradient augmentation instance is initialized and lighting position is set to random (None). The lighting direction is set to 90 degree (90) and the lighting mode is set to Gausian method. The lighting transparency is set 50 precent (0.5).

Code example:

lighting_gradient_gaussian = LightingGradient(light_position=None,
                                              direction=90,
                                              max_brightness=255,
                                              min_brightness=0,
                                              mode="gaussian",
                                              transparency=0.5
                                              )

img_lighting_gradient_gaussian = lighting_gradient_gaussian(image)
cv2.imshow("lighting_gradient_gaussian", img_lighting_gradient_gaussian)

Augmented image:

../../../_images/lighting_gradient_gaussian.png

Example 2#

In this example, a LightingGradient augmentation instance is initialized and lighting position is set to random (None). The lighting direction is set to 45 degree (45) and the lighting mode is set to linear static method. The linear decay rate is set to 0.5 (0.5) and lighting transparency is set 50 precent (0.5).

Code example:

lighting_gradient_linear_static = LightingGradient(light_position=None,
                                              direction=45,
                                              max_brightness=255,
                                              min_brightness=0,
                                              mode="linear_static",
                                              linear_decay_rate = 0.5,
                                              transparency=0.5
                                              )

img_lighting_gradient_linear_static= lighting_gradient_linear_static(image)
cv2.imshow("lighting_gradient_linear_static", img_lighting_gradient_linear_static)

Augmented image:

../../../_images/lighting_gradient_linear_static.png