function s = seginfo(f,l,pitl,ravl,ridl,peakl)
%
% seginfo: produces a table which gives for each segment i:
%           size   a1   a0   avg-intensity   avg-row   avg-col
%      where a1, a0 are the linear coefficients of the best fit line 
%      to segment i
% On input:
%    f:     2D image
%    l:     churlabel output: combined labels
%    pitl:  churlabel output: pit labels
%    ravl:  churlabel output: ravine labels
%    ridl:  churlabel output: ridge labels
%    peakl:  churlabel output: peak labels
% On output:
%    s: the table described above
%

segs = label(ridl);     % Build segments
maxseg = max(max(segs));

s = zeros(maxseg,4);

for i1 = 1:maxseg
  segsi1 = segs==i1;
  segcnt = sum(sum(segsi1));
  s(i1,1) = segcnt;
  [indi,indj] = find(segsi1);
  indiavg = sum(indi)/segcnt;
  indjavg = sum(indj)/segcnt;
  if segcnt>4
    coefs = polyfit(indj,indi,1);
    s(i1,2) = coefs(1);
    s(i1,3) = coefs(2);
  end;
  s(i1,4) = sum(sum(f.*(segsi1)))/s(i1,1);
  s(i1,5) = indiavg;
  s(i1,6) = indjavg;
end;
