function ctr = cent2( a )

%
% ctr = cent2( a )
%
% Calculates the center of mass for a (two dimensional) image a
%

sum1 = 0;
sum2 = 0;
div  = 0;

imsiz = size( a );

for i=1:imsiz(1),
  for j=1:imsiz(2),
    if a(i,j) > 0,
      sum1 = sum1 + i*a(i,j);
      sum2 = sum2 + j*a(i,j);
      div = div + a(i,j);
    end
  end
end

sum1 = sum1/div;
sum2 = sum2/div;

ctr = [ sum1; sum2 ];
