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.
Asked
Active
Viewed 1.9k times
2
-
1What are you already tried? – Danil Asotsky Apr 28 '13 at 14:57
2 Answers
5
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);

sersem1
- 466
- 1
- 4
- 10
-
why do you need to write sum twice in mseR, mseG and mseB formulas? – Ambika Saxena Aug 24 '17 at 12:38