Equalize histogram to spread intensities. mode: global or adaptive; mask optional. Improves contrast normalization across datasets.
This transform applies histogram equalization to the input image. Histogram equalization is a method in image processing of contrast adjustment using the image's histogram.
modeUse OpenCV or Pillow equalization method. Default: 'cv'
by_channelsIf True, use equalization by channels separately,
else convert image to YCbCr representation and use equalization by Y channel.
Default: True
maskIf given, only the pixels selected by the mask are included in the analysis. Can be:
mask_paramsAdditional parameters to pass to the mask function. These parameters will be taken from the data dict passed to call. Default: ()
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)
>>>
>>> # Using a static mask
>>> mask = np.random.randint(0, 2, (100, 100), dtype=np.uint8)
>>> transform = A.Equalize(mask=mask, p=1.0)
>>> result = transform(image=image)
>>>
>>> # Using a dynamic mask function
>>> def mask_func(image, bboxes):
... mask = np.ones_like(image[:, :, 0], dtype=np.uint8)
... for bbox in bboxes:
... x1, y1, x2, y2 = map(int, bbox)
... mask[y1:y2, x1:x2] = 0 # Exclude areas inside bounding boxes
... return mask
>>>
>>> transform = A.Equalize(mask=mask_func, mask_params=['bboxes'], p=1.0)
>>> bboxes = [(10, 10, 50, 50), (60, 60, 90, 90)] # Example bounding boxes
>>> result = transform(image=image, bboxes=bboxes)