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.
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.
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.
Hello, thank you for using the code provided by Hasty. Please note that some code blocks might not be 100% complete and ready to be run as is. This is done intentionally as we focus on implementing only the most challenging parts that might be tough to pick up from scratch. View our code block as a LEGO block - you can’t use it as a standalone solution, but you can take it and add to your system to complement it. If you have questions about using the tool, please get in touch with us to get direct help from the Hasty team.
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.
Only 13% of vision AI projects make it to production, with Hasty we boost that number to 100%.
Start for free Check out our services