RandomGamma
Applies random gamma correction to the input image.
Gamma correction, or simply gamma, is a nonlinear operation used to encode and decode luminance or tristimulus values in imaging systems. This transform can adjust the brightness of an image while preserving the relative differences between darker and lighter areas, making it useful for simulating different lighting conditions or correcting for display characteristics.
gamma_limitIf gamma_limit is a single float value, the range will be (1, gamma_limit). If it's a tuple of two floats, they will serve as the lower and upper bounds for gamma adjustment. Values are in terms of percentage change, e.g., (80, 120) means the gamma will be between 80% and 120% of the original. Default: (80, 120).
epsA small value added to the gamma to avoid division by zero or log of zero errors. Default: 1e-7.
pProbability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, [100, 100, 3], dtype=np.uint8)
# Default usage
>>> transform = A.RandomGamma(p=1.0)
>>> augmented_image = transform(image=image)["image"]
# Custom gamma range
>>> transform = A.RandomGamma(gamma_limit=(50, 150), p=1.0)
>>> augmented_image = transform(image=image)["image"]
# Applying with other transforms
>>> transform = A.Compose([
... A.RandomGamma(gamma_limit=(80, 120), p=0.5),
... A.RandomBrightnessContrast(p=0.5),
... ])
>>> augmented_image = transform(image=image)["image"]- The gamma correction is applied using the formula: output = input^gamma
- Gamma values > 1 will make the image darker, while values < 1 will make it brighter
- This transform is particularly useful for:
- Simulating different lighting conditions
- Correcting for non-linear display characteristics
- Enhancing contrast in certain regions of the image
- Data augmentation in computer vision tasks
- Gamma correctionhttps://en.wikipedia.org/wiki/Gamma_correction
- Power law (Gamma) encodinghttps://www.cambridgeincolour.com/tutorials/gamma-correction.htm