Histogram Equalization in Digital Image Processing


In digital image processing, histogram equalization is a process of enhancing the contrast and improve the visual quality of an image. We can perform histogram equalization using digital tools like MATLAB. This tutorial is meant for explaining the histogram equalization in digital image processing by using MATLAB. But before that let us get a basic overview about histogram equalization

What is Histogram Equalization?

As mentioned above, histogram equalization is a technique of improving the contrast and visual quality of a digital image. Histogram equalization redistributes the values of pixel intensities throughout the image more uniformly. Overall, histogram equalization is a technique of balancing the pixel intensities of an image.

  • A histogram is a graph or figure that shows the frequency distribution of pixel intensities in an image.

  • Histogram equalization of an image involves several different processes such as computing cumulative distribution function (CDF), transformation function, and then applying these functions to equalize the image.

  • Histogram equalization is widely used in various fields such as to enhance medical images, satellite images, scanned documents, and more.

Now, let us know some important points about histogram equalization which are very important while using it on an image.

Important Points about Histogram Equalization

The following are some key points that we should keep in mind while using it in image processing:

  • Histogram equalization is a global image enhancement process, as it utilizes the histogram of the entire image to perform enhancement.

  • Histogram equalization is not a suitable technique to enhance the visual quality of all kinds of images, as it can create unrealistic enhancements.

  • Histogram equalization is considered an effective method to enhance low contrast images.

Now, let us see the steps involved in histogram equalization using MATLAB.

How to Perform Histogram Equalization using MATLAB?

In MATLAB, there is a built−in function 'histeq' that is used to perform histogram equalization of a grayscale image.

The step−by−step process to perform histogram equalization using MATLAB is explained below:

Step (1) − Read the input image using the “imread” function.

img = imread('Image.jpg');

Step (2) − Convert the input image to grayscale for processing. Do this as follows:

gray_img = rgb2gray(img);

Step (3) − Use the “histeq” function to perform histogram equalization of the grayscale image. Do this as follows:

eq_img = histeq(gray_img);

Step (4) − Display the equalized image. Do this as follows:

imshow(eq_img);

Hence, in MATLAB, the histogram equalization using the “histeq” function is a simple four step process.

Let us now take some examples to practically understand and see the result, how the histogram equalization works on images.

MATLAB Examples to Perform Histogram Equalization in Digital Image Processing

If you want to understand how to implement codes in MATLAB to perform histogram equalization in digital image processing, please explore the following examples.

Example (1)

% MATLAB code to perform histogram equalization
% Read the input image
img = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425236.jpg');

% Convert the input image to grayscale
gray_img = rgb2gray(img);

% Perform histogram equalization using the “histeq” function
eq_img = histeq(gray_img);

% Display the original gray image, histogram of gray image, histogram of equalized image, and equalized image
subplot(2, 2, 1);
imshow(gray_img);
title('Original Image');

subplot(2, 2, 2);
imhist(gray_img);
title('Histogram of Gray Image');

subplot(2, 2, 3);
imhist(eq_img);
title('Histogram of Equalized Image');

subplot(2, 2, 4);
imshow(eq_img);
title('Equalized Image');

Output

Code Explanation

In this MATLAB code, we start by reading the input image, which is an RGB image. So, next we convert it to grayscale for processing. After that we perform the histogram equalization of the image to enhance its visual appearance. This is done by using the “histeq” function. Finally, we display the original grayscale image and its histogram, and the equalized image and its histogram. These outputs are shown in the above image.

Let us take another example with a different image for better clarity.

Example (2)

% MATLAB code to perform histogram equalization
% Read the input image
img = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425269.jpg');

% Convert the input image to grayscale
gray_img = rgb2gray(img);

% Perform histogram equalization using the “histeq” function
eq_img = histeq(gray_img);

% Display the original gray image, histogram of gray image, histogram of equalized image, and equalized image
subplot(2, 2, 1);
imshow(gray_img);
title('Original Image');

subplot(2, 2, 2);
imhist(gray_img);
title('Histogram of Gray Image');

subplot(2, 2, 3);
imhist(eq_img);
title('Histogram of Equalized Image');

subplot(2, 2, 4);
imshow(eq_img);
title('Equalized Image');

Output

Conclusion

In conclusion, histogram equalization is a method of processing of an image to improve its contrast levels and visual quality. This image processing technique analyzes and redistributes the pixel intensity values in an image to get the more balanced intensity levels.

In this tutorial, I have explained the concept of histogram equalization using MATLAB in detail. Also, I have included example programs in MATLAB programming to provide better insights on code implementation to perform the histogram equalization of an image. You can try these codes with your own images.

Updated on: 10-Oct-2023

185 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements