峰值信噪比
我需要找出两幅图像的峰值信噪比(PSNR)。我用两种不同的方式编写代码。答案是不同的。
% Read the image
I1 = imread('Image1.bmp');
I2 = imread('Image2.bmp');
方法 1
P = 255;
MSE =0;
MSE = mean((I1(:)-I2(:)).^2);
PSNR = 10*log10(P^2/MSE);
方法 2
I3 = 0;
for i=1:512
for j=1:512
I3 = I3 + (I1(i,j)-I2(i,j))^2;
end
end
Sum = mean(I3);
Sum1 = 255^2/Sum;
PSNR = 10*log10(Sum1);
对于方法 1,我得到的值为 30.1131,对于方法 2,我得到的值为 24.0654。我不确定为什么价值观不同。需要一些帮助。
I need to find out the peak-signal noise ratio(PSNR) of two images. I wrote the code in two different ways. The answer came out to be different.
% Read the image
I1 = imread('Image1.bmp');
I2 = imread('Image2.bmp');
Method1
P = 255;
MSE =0;
MSE = mean((I1(:)-I2(:)).^2);
PSNR = 10*log10(P^2/MSE);
Method 2
I3 = 0;
for i=1:512
for j=1:512
I3 = I3 + (I1(i,j)-I2(i,j))^2;
end
end
Sum = mean(I3);
Sum1 = 255^2/Sum;
PSNR = 10*log10(Sum1);
For Method 1, i got a value of 30.1131 and for method 2, i got a value of 24.0654. I am not sure why the values are different. Need some help on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在方法 2 中,
I3
只是一个标量,并且是平方差之和。获取标量的mean()
将返回相同的值。错误在于您没有根据图像中的元素数量对I3
进行标准化。您应该将方法 2 中的相应行更改为,它应该可以正常工作。更一般地说,应该是
In Method 2,
I3
is just a scalar and is the sum of the squared differences. Taking themean()
of a scalar will return the same value. The mistake is that you haven't normalizedI3
by the number of elements in the image. You should change the corresponding line in Method 2 toand it should work correctly. More generally, it should be