% finds the horizontal distance between the two blobs in the image
% If only 1 large blob, then returns 0
function del2 = finddist(bimage,fig6)

  labs=mybwlabel(bimage,4);  % get regions
  if fig6 > 0
    figure(fig6)
    RGB = label2rgb(labs, @jet, 'k');
    imshow(RGB)
  end

  % get region properties, make sure there are at least 2 regions
  stats = regionprops(labs,['basic']);
  [N,W] = size(stats);
  if N < 2
    del2 = 0;
    return
  end

  % do bubble sort on regions in case there are more than 2
  for i = 1 : N-1
    for j = i+1 : N
      if stats(i).Area < stats(j).Area
        tmp = stats(i);
        stats(i) = stats(j);
        stats(j) = tmp;
      end
    end
  end

  % make sure that there are at least 2 big regions
  if stats(1).Area < 100 | stats(2).Area < 100 
    del2 = 0;     
    return
  end

  % get left and right boxes of 2 largest
  lc = stats(1).Centroid;
  rc = stats(2).Centroid;
  lbb = stats(1).BoundingBox;
  rbb = stats(2).BoundingBox;
  if lc(1) > rc(1)
    tmp = lbb;
    lbb = rbb;
    rbb = tmp;
  end

  % get distance between left edge of right box and right edge
  % of left box
  del2= rbb(1) - (lbb(1)+lbb(3));
