function t = rthinc(a,h)
%   thin column response to one row
%       t = rthinc(a,h)

%  rthinr: replace any connected column neighbors in a segment
%          by a single one of them at the max height
%
%  on input:
%
%    a:     2D array of labeled ridge segments
%    h:     2D array of heights at pixels
%
%  on output:
%
%    t:	    2D array of thinned (vertically) ridge segments
%
%  Authors:	Tom Henderson
%		Univ of Utah
%		8 Sept 1996
%

t = a;
lmax = max(max(t));
for l1 = 1:lmax
  [a1,ioff,joff] = lext(t,l1);
if l1 == 0
a1
end
  [m1,n1] = size(a1);
  for i1 = 1:m1
    for j1 = 1:n1
      if a1(i1,j1)>0
       g = getcol(a1,i1,j1);
       [gmax,two] = size(g);
       if gmax>1
         imax = 1;
         hmax = h(g(1,1)+ioff,g(1,2)+joff);
         for g1 = 2:gmax
           hval = h(g(g1,1)+ioff,g(g1,2)+joff);
           if hval>hmax
             imax = g1;
             hmax = hval;
           end
         end
         for g1 = 1:gmax
           if g1~=imax
             t(g(g1,1)+ioff,g(g1,2)+joff) = 0;
             a1(g(g1,1),g(g1,2)) = 0;
           end
	 end
        end
      end
    end
  end
end
