Histogram Equalization in RGB

6 次查看(过去 30 天)
Jony
Jony 2014-10-28
回答: DGM 2025-3-28
Hi,
How can I practice HistogramEqualization on RGB at 3 channels? What does it has available function to do this?, I know it just support to GrayScale.
Thanks!

回答(2 个)

Samayochita
Samayochita 2025-3-28
编辑:Samayochita 2025-3-28
Hi Jony,
In MATLAB, the “histeq” function works only on grayscale images. There are three options available to you depending on what you want to do:
  1. You could convert the image to grayscale.
  2. You could histogram equalize each channel individually
  3. You could convert the image into the LAB or HSV colour space, histogram equalize the L or V component, then convert back into RGB. Applying histogram equalization to each RGB channel separately can distort colors because it processes each channel independently.I tend to prefer the last option for colour images because it enhances contrast while preserving colors. Therefore, one method will be an enhanced grayscale image, and the other two will be an enhanced colour image.
Convert to grayscale then equalize:
G = imread('image1.jpg');
G = histeq(rgb2gray(G));
figure; imshow(G);
Equalize each channel individually:
G = imread('image1.jpg');
for i = 1 : size(G, 3)
G(:,:,i) = histeq(G(:,:,i));
end
figure; imshow(G);
Convert to HSV, histogram equalize the V channel then convert back:
G = imread('image1.jpg');
Gh = rgb2hsv(G);
Gh(:,:,3) = histeq(Gh(:,:,3));
G = im2uint8(hsv2rgb(Gh));
figure; imshow(G);
The “rgb2hsv” function is used to convert a coloured image to HSV.
Note that the output of "hsv2rgb" will be a “double” type image and so assuming that the original input image was “uint8”, use the “im2uint8” function to convert from “double” back to “uint8”.
For more information on “rgb2grey”, “hsv2rgb”, “rgb2hsv”, “histeq” functions, please refer to the following documentation links:
I hope this helps you perform histogram equalization in your image.

DGM
DGM 2025-3-28
The following links show global and adaptive histogram equalization as applied in RGB, HSV, unconstrained LAB, and chroma-constrained LCHab, using basic tools and third-party convenience tools.

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by