function psnr=psnr(orig,proc)
% FUNCTION
%    psnr = db(orig,proc,echo)
% PURPOSE
%  Determination of the PSNR in dB
% PARAMETERS
%  INPUT:
%    orig         - matrix with original picture data
%    proc         - proccesed image data matrix
%  OUTPUT:
%    psnr         - value of PSNR

s=size(orig);
rows=s(1);
columns=s(2);
maxvalue=255;

sum=0;
for column=1:columns
  for row=1:rows
    sum=sum+(orig(row,column)-proc(row,column))^2;
  end;
end;
psnr=0;

if sum~=0  % PSNR formula:
   psnr=10*log10(maxvalue^2*rows*columns/sum);
else
   psnr=1000000;
end;

% Rounding to 2 digits after comma
psnr=round(psnr*100)/100;
s=num2str(psnr);
disp(['PSNR = ' s ' dB']);

