function ridge = rr2lab(f,l)
% returns ridge ravine image
%     r = rr2lab(f,l)
%
%   f: image array
%   l: window size for bicubic approximation

%  approximates l by l area with bicubic; then determines principal
%  curvature direction; then uses bicubic approximation to get some
%  samples along the max curvature direction; then fits a quadratic
%  to that data; then checks if there's a min or max near the pixel. 

[m,n] = size(f);
[f1,f2,f3,f4,f5,f6,f7,f8,f9,f10] = bicubicm(f,l);
ridge = zeros(m,n);

alpha = atan2(f5,(f6-f4))/2;
for i1 = 1:m
  for j1 = 1:n
    if alpha(i1,j1)<0
      alpha(i1,j1) = alpha(i1,j1)+pi;
    end
  end
end
sa = sin(alpha); ca = cos(alpha);

rhovec = -2:2;
for i1 = 1:m
  for j1 = 1:n
    count = 0;
    for rho = -2:2
      count = count+1;
      r = rho*ca(i1,j1);
      c = rho*sa(i1,j1);
      val(count) = bicubicw(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,i1,j1,r,c);
    end
    [p,S] = polyfit(rhovec,val,2);
    rtype = 0;  rmin = 10;
    if p(1)<0 & abs(p(1))>eps
      rtype = 1;
    elseif p(1)>0 & abs(p(1))>eps
      rtype = 2;
    end
    if rtype ~= 0
      rmin = -p(2)/(2*p(1));
    end
    if abs(rmin)>1
      rtype = 0;
    end
    ridge(i1,j1) = rtype;
  end
end
