What is Color Histogram Equalization in MATLAB?


In digital image processing, there is a technique called histogram equalization which is used to enhance the visual quality of an image by manipulating contrast in the image. Histogram equalization improves the quality of an image by redistributing the pixel values across the entire image, so that the histogram of the image can be uniformly distributed.

Histogram is nothing but the frequency of occurrence of each pixel intensity value. Sometimes, we see that the pixel intensities in an image are concentrated in a particular range and results in the poor visual quality of the image. Histogram equalization is used to resolve this issue by manipulating the pixel intensity levels so that they can be uniformly distributed over the entire available range.

In this tutorial, we will learn about the color histogram equalization and how to apply it to an image in MATLAB.

Color Histogram Equalization in MATLAB

In MATLAB, we can enhance the visual quality of a color image by redistributing the pixel intensities of its different color channels. This technique is called color histogram equalization.

Color histogram equalization improves the contrast distribution in the image and makes the image visually appealing.

Process of Color Histogram Equalization

The step-by-step process to perform color histogram equalization in MATLAB is described below −

  • Step (1) − Read the input color image.

  • Step (2) − Convert the input RGB image into lab color image.

  • Step (3) − Perform color histogram equalization on the image.

  • Step (4) − Conver the lab color image back to the RGB image.

  • Step (5) − Display the enhance image.

Hence, color histogram equalization in MATLAB is a straightforward five step process.

Matlab Example

Now, let us see the implementation of a MATLAB program to perform color histogram equalization of an image.

The following MATLAB program demonstrates the implementation of color histogram equalization in MATLAB programming.

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

% Convert the RGB image to lab color image
lab_img = rgb2lab(img);

% Extract the luminance channel of the lab image
L = lab_img(:, :, 1);

% Perform color histogram equalization of L channel
che = histeq(L);
enhanced_lab_img = lab_img;	% Copy the original lab image to the variable 'enhanced_lab_img'
enhanced_lab_img(:, :, 1) = che;	% Assign the equalized L-channel to L-channel of the 'enhanced_lab_img'

% Convert the equalized image back to RGB image
enhanced_rgb_img = lab2rgb(enhanced_lab_img);

% Display the original and enhanced images
subplot(1, 2, 1), imshow(img), title('Original Image');
subplot(1, 2, 2), imshow(enhanced_rgb_img ), title('Enhanced Image');

Output

Explanation

In this MATLAB program, firstly we read the input color image using the 'imread' function and store it in a variable 'img'. Then, we convert the input RGB image to a Lab Color image using the 'rgb2lab' function and store it in a variable 'lab_img'. In the lab color image, the luminance channel of the image can be easily separated from its color information that helps to perform color histogram equalization without influencing its color balance.

After that we separate the color luminance channel and apply histogram equalization to it using the 'histeq' function.

Next, we convert the assign the enhanced luminance channel to the luminance channel of the original lab image, and convert the enhanced lab image back to the RGB image using the 'lab2rgb' function.

Finally, we display the original image and the enhanced image using the 'disp' function.

Conclusion

This is all about performing color histogram equalization on an image to improve its visual quality. It is quite simple and straightforward process to improve contrast level of an image. In the above given MATLAB, you can replace the address of the image with yours one for experiment.

Updated on: 06-Sep-2023

125 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements