function cnt = cooc(x,k)
%
[m,n] = size(x);
cnt = zeros(m,n);
k2 = (k-1)/2;

xl = x(1:m,2:n);
cnt = x(1:m,1:n-1)*2 + xl;

for i1 = k2+2:m-k2
  for j1 = k2+2:n-k2
    cnt(i1,j1) = sum(sum(x(i1-k2:i1+k2,j1-k2:j1+k2)));
  end;
end;

