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

%  rthinc: replace any connected row 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 (horizontally) ridge segments
%
%  Authors:	Tom Henderson
%		Univ of Utah
%		8 Sept 1996
%

t = a;
lmax = max(max(t));
for l1 = 1:lmax
% l1
  [a1,ioff,joff] = lext(t,l1);
  [m1,n1] = size(a1);
  for i1 = 1:m1
    for j1 = 1:n1
      if a1(i1,j1)>0
        g = getrow(a1,i1,j1);
        [gmax,two] = size(g);
        if gmax>1
          jmax = 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
             jmax = g1;
             hmax = hval;
           end
         end
         for g1 = 1:gmax
           if g1~=jmax
             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
