Brightness#

class augraphy.augmentations.brightness.Brightness(brightness_range=(0.8, 1.4), min_brightness=0, min_brightness_value=(20, 50), numba_jit=1, p=1)[source]#

Bases: Augmentation

Adjusts the brightness of the whole image by a chosen multiplier.

Parameters:
  • brightness_range (tuple, optional) – Pair of ints determining the range from which to sample the brightness shift.

  • min_brightness (int, optional) – Flag to enable min brightness intensity value in the augmented image.

  • min_brightness_value (tuple, optional) – Pair of ints determining the minimum brightness intensity of augmented image.

  • numba_jit (int, optional) – The flag to enable numba jit to speed up the processing in the augmentation.

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

static adjust_min_brightness(image, min_brightness_value)[source]#

Increase image pixel intensity by value of 10 in each iteration until reaching the min brightness value.

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

  • min_brightness_value (int) – The minimum brightness of value of each pixel.

Overview#

The Brightness augmentation adjusts the brightness of the whole image by a chosen multiplier.

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 Brightness augmentation instance is initialized and the brightness range is set to 1.5 to 2 (1.5, 2) times of original brightness. Flag to enable min brightness is disabled.

Code example:

brightness_brighten= Brightness(brightness_range=(1.5, 2),
                       min_brightness=0,
                    )

img_brightness_brighten= brightness_brighten(image)
cv2.imshow("brightness_brighten", img_brightness_brighten)

Augmented image:

../../../_images/brightness_brighten.png

Example 2#

In this example, a Brightness augmentation instance is initialized and the brightness range is set to 0.2 to 0.8 (0.2, 0.8) times of original brightness. Flag to enable min brightness is enabled (1) and the minimum pixel value is set to between 120 to 150 (120,150).

Code example:

brightness_dimmer= Brightness(brightness_range=(0.2, 0.8),
                                min_brightness=1,
                                min_brightness_value=(120, 150),
                        )

img_brightness_dimmer= brightness_dimmer(image)
cv2.imshow("brightness_dimmer", img_brightness_dimmer)

Augmented image:

../../../_images/brightness_dimmer.png