本文介绍了直方图均衡结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 默认情况下使用64个bin来均衡直方图。您正在使用 histeq 的默认实现。尝试做:

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

builtInEqualizationI = histeq(grayI, 256);

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

... 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.

这篇关于直方图均衡结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:02