function idm = tmidm(P,k,l)
%
% tmidm - Compute inverse difference moment of cooccurrence matrix
% On input:
%     P: 2D cooccurrence matrix
%     k: power of gray level difference
%     l: power of probability
% On output:
%     idm: inverse difference moment
% Call:
%     idm = tmidm(P,k,l);
%

[m,n] = size(P);
sum = 0;
for r = 1:m
  for c = 1:n
    denom = ((abs((r-1)-(c-1)))^k);
	if denom ~= 0
      sum = sum + (P(r,c)^l)/denom;
	end
  end
end
idm = sum;
