Image Processing — Histogram Equalization: Part 4

Kavini Welarathne
3 min readJul 12, 2022

--

Today, I want to share about Histogram Equalization and its practices.

Goal

As part of today’s post, I will start out by

(1). Briefly explaining Histogram Equalization

(2). How to apply Histogram Equalization and

(3). Color Histogram Equalization

If you are a complete beginner at Histogram, I recommend to you have a quick look at my Histogram: Part 3 article published previously.

What is Histogram Equalization?

Histogram Equalization is a computer image processing technique used to improve contrast in images.

How it works

To enhance the image’s contrast,
-> it spreads out the most frequent pixel intensity values or
-> stretches out the intensity range of the image.

Now let’s try to understand its practices.

Apply Histogram Equalization

1. How to improve the contrast of the dark image

Here we use cv2.equalizeHist() function to equalized the image. It is a OpenCV function.

The input image and Output image

Input Image — — — — — — — — — — — — — — — — — — — — — — — → Output image

Plotted Histograms

2. How to improve the contrast of the color image

The input image and Output image

Input Image — — — — — — — — — — — — — — — — — — — — — — — → Output image

Plotted Histograms

3. How to improve the contrast of a dark and bright image (Both together)

Ugh…give me a break. Anyway, let’s take a look at the steps we need to take:

Step 1: Import the images

Step 2: Create original images histograms

Step 3: Equalized the images using cv2.equalizeHist() function

Step 4: Create equalized images histograms

Step 5: Plot the histograms (originals and equalized)

Step 6: Save equalized images to another location.

Plotted Histograms

Finally, we are considering the…

Color Histogram Equalization

How to improve the contrast of the color image

Plotted Histograms

As you can see, all the generated new images’ contrast has been enhanced and their histogram has also been equalized.

And…That’s it for now.

Note: Here I’ve attached an image file for your convenience.

This article is part of a series and my next article is regarding:

1. Negative transformation

2. Power-law transformation

3. Log transformation

If you enjoyed this piece, please hit the clap button 👏

See you guys in the next article! ❤️ ✌

--

--

Kavini Welarathne
Kavini Welarathne

Written by Kavini Welarathne

Software Engineer | Researcher |

No responses yet