?? 灰度直方圖.txt
字號:
clc
clear
fn='rice.tif';
I=imread (fn);
J=I;
%計算灰度圖象的直方圖數(shù)據(jù)
L=256; %灰度級
Ps = zeros(L,1); %統(tǒng)計直方圖結(jié)果數(shù)據(jù)
nk=zeros(L,1);
[row,col]=size(I);
n=row*col; %總像素個數(shù)
for i = 1:row
for j = 1:col
num = double(I(i,j))+1; %獲取像素點灰度級
nk(num) = nk(num)+1; %統(tǒng)計nk
end
end
%計算直方圖概率估計
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)');
%figure(4),imhist(hist);
%p=imhist(hist); %生成直方圖函數(shù),返回灰度圖象直方圖數(shù)據(jù)
%figure(5),plot(p);
看源代碼的方法
>demo
>edit histeq
>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -