www.pudn.com > DWM.rar > msepsnr.m, change:2007-07-21,size:897b


%% Calculate the Mean Square Error and Peak Signal-to-Noise Ratio of the image. %% 
% function [mse,psnr]=msepsnr(ImageOrg,ImageNew) 
% ImageOrg: the original image; ImageNew: the processed image; 
%% Programmed by S. Q. SHI in Jun.26, 2007. %% 
 
function [mse,psnr]=msepsnr(ImageOrg,ImageNew) 
% the intensity of the image should locate between 0 and 255; 
if max(ImageOrg(:))<1 
    ImageOrg=round(ImageOrg*255); 
end 
if max(ImageNew(:))<1 
    ImageNew=round(ImageNew*255); 
end 
[Row,Col]=size(ImageOrg); % obtain the necessary parameters; 
% temp1=0; temp2=0;   % temperaory values; 
% temp1=round(ImageOrg-ImageNew); 
% for i=1:Row 
%     for j=1:Col 
%         temp2=temp2+temp1(i,j).^2; 
%     end 
% end 
temp=(abs(ImageNew-ImageOrg)).^2; 
mse=sum(temp(:))/(Row*Col); 
 
% mse=temp2/(Row*Col); 
psnr=10*log10(255*255/mse); % Here 255 represents the gray-level of the imgae. 
clear temp*