How to Perform Contrast Enhancement Using Histogram Equalization in MATLAB?


In digital image processing, the process of improving visual quality and clarity of a digital image by changing the color intensities is referred to as "contrast enhancement".

Contrast enhancement is an important image processing task in various fields such as photography, remote imaging, medical imaging, etc. We can use various tools to perform contrast enhancement of an image. In this tutorial, I will explain the process of performing contrast enhancement using histogram equalization in MATLAB.

What is Contrast Enhancement?

In digital image processing, contrast enhancement is a basic image processing task performed to improve visual quality of an image to make it more visually appealing.

  • Contrast enhancement of a digital image is performed by changing the pixel intensities of different color channel of the image. It makes an image clearer and more detailed.

  • Contrast enhancement is one of the vital processes in various fields like medical imaging, photography, microscopic imaging, computer vision, and more.

  • We can perform contrast enhancement of an image using MATLAB. MATLAB provides various efficient techniques to perform contrast enhancement, such as histogram equalization, contrast stretching, contrast limited adaptive histogram equalization, adaptive contrast enhancement, etc.

In this tutorial, we will learn to perform contrast enhancement of an image using histogram equalization method in MATLAB.

Contrast Enhancement Using Histogram Equalization in MATLAB

Histogram equalization is one of the most commonly used method to alter the intensity values of pixels in an image to improve the visual quality. We can use histogram equalization to enhance the contrast of an image.

In MATLAB, the contrast enhancement is performed by using a built-in function named, "histeq".

Here is the step-by-step process to perform the contrast enhancement using the histogram equalization method in MATLAB.

  • Step (1) − Read the input image using the "imread" function.

  • Step (2) − Convert the input image to grayscale to apply histogram equalization. For this, use the "rgb2gray" function.

  • Step (3) − Perform contrast enhancement of gray image using the "histeq" function.

  • Step (4) − Display the enhanced image using the "imshow" function.

In MATLAB, contrast enhancement using the histogram equalization is a four-step process.

Example

Let us now take an example to understand the code implementation in MATLAB to perform contrast enhancement using histogram equalization.

% MATLAB code to perform contrast enhancement using 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 contrast enhancement using histogram equalization
enhanced_img = histeq(gray_img);

% Display the input and enhanced images
figure;
subplot(1, 2, 1);
imshow(gray_img);
title('Input Image');

subplot(1, 2, 2);
imshow(enhanced_img);
title('Enhanced Image');

Output

When you run this code, it will produce the following output −

Explanation

In this example, we start by reading the input image using the "imread" function. Then, we convert the input image from RGB color format to grayscale using the "rgb2gray" function. Next, we use the "histeq" function to perform contrast enhancement of the image. Finally, we display the grayscale version of the input image and the enhanced image using the "imshow" function.

Conclusion

In conclusion, contrast enhancement is a way of improving the visual quality of an image by manipulating the pixel intensity values in the image. We can use MATLAB to perform contrast enhancement of an image. MATLAB provides several methods to accomplish this task, the most commonly used method is histogram equalization.

In this tutorial, I explained the step-by-step process of contrast enhancement of an image using the histogram equalization in MATLAB.

Updated on: 06-Oct-2023

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements