为什么我用MATLAB和C语言计算图像信噪比PSRN结果不一样
柯南与企鹅 2017-03-09 03:20:10
以下是两个代码,采用的公式一样:
********************************************************
function PSNR = psnrnew(f1, f2)
%计算两幅图像的 峰值信噪比
k = 8;
%k为图像是表示地个像素点所用的二进制位数,即位深。
fmax = 2.^k - 1;
a = fmax.^2;
e = im2uint8(f1) - im2uint8(f2);
[m, n] = size(e);
b = mean(sum(sum(e.^2)));
PSNR = 10*log10(m*n*a/b);
**********************************************************************************************
****************************************************************************************************
int temp2=0;
for ( i =0;i<image_height;i++)
{
for ( j=0;j<image_width;j++)
temp2 = temp2 + (a[i][j]-Re[i][j])*(a[i][j]-Re[i][j]);
}
double MSE=0.0;
MSE = temp2/(512*512);
// double SNR=255*255/temp2*512*512;
//SNR=10*log10(SNR);//SNR即为信噪比
printf ("MSE=%.3f\n",MSE);
double PSNR=(255*255)/MSE;
PSNR=10*log10(PSNR);//PSNR即为峰值信噪比
printf ("PSNR=%.4f\n",PSNR);