If you have ever worked on a Computer Vision project, you might know that using augmentations to diversify the dataset is the best practice. On this page, we will:

  • Сover the Equalize augmentation;

  • Check out its parameters;

  • See how Equalize affects an image;

  • And check out how to work with Equalize using Python through the Albumentations library.

Let’s jump in.

To define the term, Equalize is an augmentation that equalizes the image histogram. In other words, this augmentation enhances image contrast. Let’s dive a bit deeper into how it works.

If you are unfamiliar with the topic, each image can be represented in the form of a histogram featuring the intensity distribution of an image.

Image source: Wikipedia

In the picture above, you can see a simple example of such a representation. In this case, the x-axis is the brightness scale (from black on the left to white on the right). On the other hand, the y-axis features the number of pixels of a certain intensity on an image. So, in a sense, the histogram represents the number of pixels for each brightness value.

As mentioned above, Equalize performs the Histogram Equalization image processing technique, enhancing the image contrast. To do so, the algorithm spreads the most frequent intensity values, enhancing an image's overall contrast.

Image source: Wikipedia
For color images, applying Histogram Equalization to each one of the Red, Green, and Blue channels might not be a great idea. Such an approach will result in massive changes in the initial color balance. So, to avoid messing up your result, please convert your image to another color space such as HSL or HSV. Then, apply the algorithm to the luminance or value channel (depending on your color space format). This will help you enhance the image’s contrast without messing with the hue or saturation.
  • Probability of applying transform - defines the likelihood of applying Equalize to an image;

  • Use OpenCV or Pillow equalization mode - OpenCV and Pillow libraries have bit different equalization modes, so it is up to you to decide which one you like more;

  • Equalize by channel - when toggled on, each channel of an image will be equalized separately. When toggled off, a picture is converted to YCbCr representation and equalized by the Y channel.

Original image
Image after Equalize is applied to it as a whole
      import albumentations as albu
from PIL import Image
import numpy as np

transform =albu.augmentations.transforms.Equalize()
image = np.array(Image.open('/some/random/image.png'))
augmented_image = transform(image=image)['image']

# We have the equalized image in augmented_image.

Boost model performance quickly with AI-powered labeling and 100% QA.

Learn more
Last modified