图像PSNR值及MSE值的计算

时间:2024-03-04 07:23:42
% 图像峰值信噪比PSNR、均方根误差MSE
% By lyqmath
% Xidian University 
function [PSNR, MSE] = psnr(X, Y)
% 计算峰值信噪比PSNR、均方根误差MSE
% 如果输入Y为空,则视为X与其本身来计算PSNR、MSE

if nargin<2
    D = X;
else
    if any(size(X)~=size(Y))
        error(\'The input size is not equal to each other!\');
    end
    D = X-Y;
end
MSE = sum(D(:).*D(:))/prod(size(X));
PSNR = 10*log10(255^2/MSE);
最后使用的时候注意把X,Y转换成double值...