Power noise ratio (PSNR) of a color jpeg image

I have an original image and a distorted image of the original. I want to calculate PSNR of a distorted image in order to measure distortion in dB. Image type color jpeg.

+2


source to share


2 answers


I don't know what you've used before, but you can use the following code to calculate the PSNR of the modified 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);

      

+5


source


Here's a vector implementation:

mse = mean(mean((im2double(I) - im2double(K)).^2, 1), 2);
psnr = 10 * log10(1 ./ mean(mse,3));

      

It should work for integer and floating point images, in both grayscale and color images.



I am using the following PSNR definition :

mse

psnr

+4


source







All Articles