function PSNR=PSNRgray(original, distorted, W, H)
% Function for computation of PSNR of YUV files with luma.
% PSNR=PSNRgray(original, distorted, W, H), where "original" and 
% "distorted" contain path to original and distorted YUV files
% and W and H are width and height respectively.
% For luma YUV files only.
% Created: May, 2013. Ondrej Zach.

fidO=fopen(original);
fidD=fopen(distorted);
Orig=fread(fidO, '*uint8');
Dist=fread(fidD, '*uint8');
fclose('all');
nFrames=length(Orig)/(W*H)
Orig=reshape(Orig, W, H, nFrames);
Dist=reshape(Dist, W, H, nFrames);
Orig=permute(Orig, [2 1 3]);
Dist=permute(Dist, [2 1 3]);
ErrorImage=Orig-Dist;
clear Dist Orig
ErrSq=ErrorImage.^2;
for i=1:nFrames
    mse=sum(sum(ErrSq(:,:,i)))/(738*432);
    PSNR(i)=10*log10(255.^2/mse);
end
PSNR=PSNR';





