1 function PSNR_Value = PSNRCal(X,Xhat)
5 % Read the dimensions of the image.
6 [rows columns ~] = size(I);
8 % Calculate mean square error of R, G, B.
9 mseRImage = (double(I(:,:,1)) - double(Ihat(:,:,1))) .^ 2;
10 mseGImage = (double(I(:,:,2)) - double(Ihat(:,:,2))) .^ 2;
11 mseBImage = (double(I(:,:,3)) - double(Ihat(:,:,3))) .^ 2;
13 mseR = sum(sum(mseRImage)) / (rows * columns);
14 mseG = sum(sum(mseGImage)) / (rows * columns);
15 mseB = sum(sum(mseBImage)) / (rows * columns);
17 % Average mean square error of R, G, B.
18 mse = (mseR + mseG + mseB)/3;
20 % Calculate PSNR (Peak Signal to noise ratio).
21 PSNR_Value = 10 * log10( 255^2 / mse);