简体   繁体   中英

Histogram Equalization Results

I am trying to code histogram equalization by my self, but the results are different from the built in function in matlab histeq . Any suggestions why is this happening?. I attached the code and the results. 输出图像 输出直方图

%% Histogram Equalization
close all
clear all
%%
I = imread('Iris_virginica.jpg');
grayI = rgb2gray(I);
[m,n] = size(grayI);
L = 256;
[counts,x] = imhist(grayI);
myCDF = cumsum(counts)/(m*n);
equalizedI = (L-1)*myCDF(double(grayI)+1);
equalizedI = uint8(equalizedI);
histMyOut = imhist(equalizedI);
builtInEqualizationI = histeq(grayI);
histBuiltInEqu = imhist(builtInEqualizationI);
%%
figure
subplot(1,3,1), stem(x,counts), title('Histogram');
subplot(1,3,2), stem(x,myCDF), title('Commulative Distribution');
subplot(1,3,3), stem(x,imhist(equalizedI)), title('Equalized');

figure
subplot(1,3,1),imshow(grayI), title('Input image');
subplot(1,3,2), imshow(equalizedI), title('Equalized image (mine)');
subplot(1,3,3), imshow(builtInEqualizationI), title('Equalized image (matlab)');

figure
subplot(1,3,1), stem(x,counts), title('Histogram');
subplot(1,3,2), stem(x,histMyOut), title('Equalized Histogram (mine)');
subplot(1,3,3), stem(x,histBuiltInEqu), title('Equalized Histogram (matlab)');

difference = abs(equalizedI-builtInEqualizationI);
figure, imshow(difference,[]);

histeq by default uses 64 bins to equalize your histogram. You are using the default implementation of histeq . Try doing:

builtInEqualizationI = histeq(grayI, 256);

... to specify 256 bins for equalization as your manual code is using that many bins for the equalization. The second parameter overrides the default and informs histeq to use that many bins to perform the equalization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM