本文介绍了彩色jpeg图像的功率信号噪声比(PSNR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有原始图像和原始图像的扭曲图像。我想计算失真图像的PSNR,这样我就可以用dB来测量失真。图像类型为彩色jpeg。
I have an original image and a distorted image of the original one. I want to calculate the PSNR of the distorted image, so that I can measure the distortion in dB. Image type is colored jpeg.
推荐答案
我不知道您以前使用过什么,但可以使用以下代码计算PSNR已更改的图像:
I dont know what you have used before but you can use the following code to calculate the PSNR of changed image:
I = imread('original.jpg');
Ihat = imread('changed.jpg');
% Read the dimensions of the image.
[rows columns ~] = size(I);
% Calculate mean square error of R, G, B.
mseRImage = (double(I(:,:,1)) - double(Ihat(:,:,1))) .^ 2;
mseGImage = (double(I(:,:,2)) - double(Ihat(:,:,2))) .^ 2;
mseBImage = (double(I(:,:,3)) - double(Ihat(:,:,3))) .^ 2;
mseR = sum(sum(mseRImage)) / (rows * columns);
mseG = sum(sum(mseGImage)) / (rows * columns);
mseB = sum(sum(mseBImage)) / (rows * columns);
% Average mean square error of R, G, B.
mse = (mseR + mseG + mseB)/3;
% Calculate PSNR (Peak Signal to noise ratio).
PSNR_Value = 10 * log10( 255^2 / mse);
这篇关于彩色jpeg图像的功率信号噪声比(PSNR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!