MATLAB画灰度图像直方图的代码
I=imread('cameraman.tif');
[M N]=size(I);%求出图片大小
y=zeros(1,256)
x=0:255;
for t=0:255
for i=1:M
for j=1:N
if I(i,j)==t
y(1,t+1)=y(1,t+1)+1;
end
end
end
end
%画图
plot(x,y)