当前位置: 代码迷 >> 综合 >> 信噪比(PSNR)
  详细解决方案

信噪比(PSNR)

热度:82   发布时间:2023-11-11 04:45:52.0

function psnr=PSNR(A,B)
%将图像A的大小赋值给变量SizeA
sizeA=size(A);
%将图像B的大小赋值给变量SizeB
sizeB=size(B);
%判断A与B的大小是否相等
if sizeA~=sizeB
error(‘Image A and B are not of the same size’)
end
if A==B
error(‘Image are idential:PSNR has infinite value’)
end
%分别找出A与B中的最大与最小灰度点值
max2_A=max(max(A));
max2_B=max(max(B));
min2_A=min(min(A));
min2_B=min(min(B));
%确定灰度值的范围在0~255
if max2_A>255 || max2_B>255 || min2_A<0 ||min2_B<0
error(‘input matrices must have values in the interval [0,255]’)
end
error_diff=A-B;
psnr=20*log10(255/(sqrt(mean(mean(error_diff)))));
disp(sprintf(‘PSNR’= + %5.2fdB’,psnr))