function rc = ridgecl(r,K);
% rc = ridgecl(r,K);
%     Label regions that have K connected horizontal ridge elements.
[m n] = size(r);
rc = zeros(m,n);
label = 0;
for i1 = 1:m
  j1 = 0;
  while j1<n
    j1 = j1+1;
    if r(i1,j1) ~=0
      count = 1;
      j2 = j1+1; more = 1;
      while more > 0
        more = 0;
        if r(i1,j2) ~= 0
          more = 1;
          count = count+1;
          j2 = j2+1;
          if j2>n
            more = 0;
          end
        end
      end
      if count>K
        label = label+1;
        for jc = j1:j1+count-1
          rc(i1,jc) = label;
        end
        j1 = j1+count;
      end
    end
  end
end
