www.pudn.com > zishiyingjiami.rar > ps.m, change:2011-12-27,size:583b


%图像峰值信噪比  
A=imread('lena128.bmp'); 
A1=imread('untitled.bmp'); 
[m,n]=size(A); 
mse_m=double(zeros(m,n)); %均方误差  
for i=1:m  
for j=1:n  
mse_m(i,j)=(A(i,j)-A1(i,j))^2;  
end  
end  
mse=sum(mse_m(1:m,1:n))/m*n;  
mse=double(mse); 
psnr=10*log(double(255*255/mse))/log(10);%峰值信噪比  
% 下面计算熵  
t(1:256)=0;   
%给每个灰度值计数  
for i=1:m  
for j=1:n  
t(A1(i,j)+1)=t(A1(i,j)+1)+1;  
end  
end  
%计算各个灰度出现频率  
for i=1:256  
t(i)=t(i)/(256*256);  
end  
entropy=0; %计算熵  
for i=1:256  
if t(i)>0  
entropy=entropy-t(i)*log(t(i))/log(2);  
end  
end