function b = lbmask(bands,f)
% b = lbmask(bands,f)
%
% Creates a matrix of non-zero values for each lane
%
% On input:
%          bands: lanes matrix of dimension # bands by 20
%              f: image function (needed for dimension of mask)
%
% On output:
%              b: non-zero down lane extent
%
[m n] = size(f);
b = zeros(m,n);
[bm bn] = size(bands);

l = 0;
for b1 = 1:bm
  below = bands(b1,18);
  above = bands(b1,19);
  eqvt = bands(b1,20);
  r1 = bands(b1,15);
  c1 = bands(b1,16);
  if above==0 & eqvt==b1
    l = l+1;
    bfirst = b1;
    b2 = below;
    rmin = max(1,bands(b1,15)-1);
    rmax = min(m,bands(b1,15)+1);
    for r = rmin:rmax
      b(r,c1) = l;
    end
%    plotb([bands(b1,15)-2,bands(b1,16),bands(b1,15),bands(b1,16)]);
    while b2~=0
      r2 = bands(b2,15);
      c2 = bands(b2,16);
      drow = abs(r2-r1);
      dcol = abs(c2-c1);
      dmax = max(drow,dcol);
      t = 0:(1/dmax):1;
      for t1 = 1:dmax+1
        r3 = round((1-t(t1))*r1 + t(t1)*r2);
        c3 = round((1-t(t1))*c1 + t(t1)*c2);
        b(r3,c3) = l;
      end
%      plotb([bands(bfirst,15),bands(bfirst,16),bands(b2,15),bands(b2,16)]);
      bfirst = b2;
      r1 = r2;
      c1 = c2;
      b2 = bands(b2,18);
    end
  end
end
