% 图像峰值信噪比PSNR、均方根误差MSE
% By lyqmath
% Xidian University
function [PSNR, MSE] = psnr(X, Y)
% 计算峰值信噪比PSNR、均方根误差MSE
% 如果输入Y为空,则视为X与其本身来计算PSNR、MSEif nargin<2D = X;
elseif any(size(X)~=size(Y))error('The input size is not equal to each other!');endD = X-Y;
end
MSE = sum(D(:).*D(:))/prod(size(X));
PSNR = 10*log10(255^2/MSE);
最后使用的时候注意把X,Y转换成double值...
转载于:https://www.cnblogs.com/cyxcw1/archive/2012/05/25/3051304.html