function R=AutoCorr2(x)
%
% AutoCorr2 2-D Autocorrelation function
%
% Example R(dx,dy)=AutoCorr2(x);
%

[M,N]=size(x);
R=zeros(M,N);
for dx=0:M-1
   for dy=0:N-1
      for i=0:M-1-dx
	 for j=0:N-1-dy
	    R(dx+1,dy+1)=R(dx+1,dy+1)+x(i+1,j+1)*x(i+1+dx,j+1+dy);
	 end;
      end;	  
      R(dx+1,dy+1)=R(dx+1,dy+1)/(M-dx)/(N-dy);
    end;
end;