直方图均衡结果

时间:2016-07-23 22:16:13

标签: image matlab image-processing histogram

我试图通过自己对直方图均衡进行编码,但结果与matlab histeq中的内置函数不同。任何建议为什么会发生这种情况?我附上了代码和结果。output images output histograms

%% 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,[]);

1 个答案:

答案 0 :(得分:2)

默认情况下,

histeq使用64个bin来均衡直方图。您正在使用histeq的默认实现。尝试做:

builtInEqualizationI = histeq(grayI, 256);

...指定256个用于均衡的分档,因为您的手动代码使用那么多分档进行均衡。第二个参数会覆盖默认值,并通知histeq使用那么多个二进制位来执行均衡。