function b = ridge2(r1)
% b = ridg2e(r1)
%    r1: output from ridge1
% returns: center locations of each connected ridge set have value 1
%          

[m n] = size(r1);
b = zeros(m,n);
a = r1;
label = 0;

for ii = 4:m-3
  for jj = 4:n-3
    if (a(ii,jj) == 16 & (a(ii,jj-1) == 2 | a(ii,jj-1) == 4) ...
     & (a(ii,jj-2) == 2 | a(ii,jj-2) == 4) ...
     & (a(ii,jj-3) == 2 | a(ii,jj-3) == 4) ...
     & (a(ii,jj+1) == 2 | a(ii,jj+1) == 8) ...
     & (a(ii,jj+2) == 2 | a(ii,jj+2) == 8) ...
     & (a(ii,jj+3) == 2 | a(ii,jj+3) == 8)) ...
     | ((a(ii,jj) == 4 & a(ii,jj+1) == 8) ...
      & (a(ii,jj-1) == 2 | a(ii,jj-1) == 4) ...
      & (a(ii,jj-2) == 2 | a(ii,jj-2) == 4) ...
      & (a(ii,jj+1) == 2 | a(ii,jj+1) == 8) ...
      & (a(ii,jj+2) == 2 | a(ii,jj+2) == 8)) 
      label = label+1;
      b(ii,jj) = label;
    end
  end
end

          
            