相关代码 |
|
clc clear I=imread ('Cameraman.bmp'); J=I; %计算灰度图象的直方图数据 L=256; %灰度级 Ps = zeros(L,1); %统计直方图结果数据 nk=zeros(L,1); [row,col]=size(I); n=row*col; %总像素个数 for i = 1:row for j = 1:col num = double(I(i,j))+1;%获取像素点灰度级 nk(num) = nk(num)+1; %统计nk end end Q=J(1,1) %计算直方图概率估计 for i=1:L Ps(i)=nk(i)/n; end figure; subplot(3,1,1);imshow(J),title('原图'); subplot(3,1,2),plot(nk),title('直方图(nk)'); subplot(3,1,3),plot(Ps),title('直方图(Ps)');
相关资源 |
|