Solarize
Invert all pixel values above a threshold.
This transform applies a solarization effect to the input image. Solarization is a phenomenon in photography in which the image recorded on a negative or on a photographic print is wholly or partially reversed in tone. Dark areas appear light or light areas appear dark.
In this implementation, all pixel values above a threshold are inverted.
threshold_rangeRange for solarizing threshold as a fraction of maximum value. The threshold_range should be in the range [0, 1] and will be multiplied by the maximum value of the image type (255 for uint8 images or 1.0 for float images). Default: (0.5, 0.5) (corresponds to 127.5 for uint8 and 0.5 for float32).
pProbability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>>
# Solarize uint8 image with fixed threshold at 50% of max value (127.5)
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.Solarize(threshold_range=(0.5, 0.5), p=1.0)
>>> solarized_image = transform(image=image)['image']
>>>
# Solarize uint8 image with random threshold between 40-60% of max value (102-153)
>>> transform = A.Solarize(threshold_range=(0.4, 0.6), p=1.0)
>>> solarized_image = transform(image=image)['image']
>>>
# Solarize float32 image at 50% of max value (0.5)
>>> image = np.random.rand(100, 100, 3).astype(np.float32)
>>> transform = A.Solarize(threshold_range=(0.5, 0.5), p=1.0)
>>> solarized_image = transform(image=image)['image']- For uint8 images, pixel values above the threshold are inverted as: 255 - pixel_value
- For float32 images, pixel values above the threshold are inverted as: 1.0 - pixel_value
- The threshold is applied to each channel independently
- The threshold is calculated in two steps:
- Sample a value from threshold_range
- Multiply by the image's maximum value:
- For uint8: threshold = sampled_value * 255
- For float32: threshold = sampled_value * 1.0
- This transform can create interesting artistic effects or be used for data augmentation
Invert: For inverting all pixel values regardless of a threshold.