function [psnr, mssim ] = psnrssim(Iref, I2, nbits, lmax)

% =======================================================================
% Edited code by zulu
%
% Last Modified: 2011-12-08
%========================================================================

%========================================================================
%Input : (1) Iref: the ref image 
%        (2) I2  : the image being compared
%        (3) lmax: max length of paths 
%========================================================================

IcutA = zeros(size(Iref,1), lmax) ;
IcutB = [ zeros(lmax, size(Iref,2)- 2*lmax) ; ones(size(Iref)-[ 2*lmax 2*lmax ]) ; zeros(lmax, size(Iref,2)-2*lmax) ] ;
Icut = [ IcutA IcutB IcutA] ; 

Irefcut = double(Iref).*double(Icut) ;
I2cut = double(I2).*double(Icut) ;

psnr = 10*log10((2^nbits)^2/(mean(mean((I2cut-Irefcut).^2)))) ; 

mssim = ssim(Irefcut, I2cut) ;


return 
