原创文章,欢迎转载。转载请注明:转载自 祥的博客
原文链接:http://blog.csdn.net/humanking7/article/details/46822709
这是参考冈萨雷斯的那个大块头和维基百科总结的。
其实Matlab里面给我们封装好了函数,用OpenCV那个直方图显示的代码还得自己写。 函数:
histeq
imhist
clear all;
clc;
%------------------------------------------------------------
%灰度均衡化,并显示图像的情况
%------------------------------------------------------------
%读进图像
[filename, pathname] = uigetfile({'*.jpg'; '*.bmp'; '*.gif'; '*.png' }, '选择图片');
%没有图像
if filename == 0
return;
end
Image = imread([pathname, filename]);
[m, n, z] = size(Image);
%转换为灰度图
if z>1
Image = rgb2gray(Image);
end
eqImage = histeq(Image);
figure(1)
subplot(2,3, 1);
imshow(Image);
title('(a)');
subplot(2,3, [2 3])
imhist(Image);
title('(b)');
subplot(2,3, 4);
imshow(eqImage);
title('(c)');
subplot(2,3, [5 6]);
imhist(eqImage);
title('(d)');