function b = bprops(l,f)
%
%  Computes Properties of bands/labels in genetics images
%
%  b = bprops(l,f)
%
% On Input :
%
% 	l : 2D Labeled ridge image
%	f : original gray-level image
%
%
%
% On Output :
%
%	b : one row per label with the following columns
%
%       1 : left column terminator
%	2 : right column terminator
%	3 : top row terminator
%	4 : bottom row terminator
%	5 : Number of pixels in label
%	6 : width of label
%	7 : height of label
%	8 : Average gray level of label
%	9 : X Coord of center
%      10 : Y Coord of center
%   11-14 : left,right,top,bottom nearest neighbors   
%   
%
%

[m,n] = size(l);
maxl=max(max(l));

b = zeros(maxl,14);

for i1 = 1:maxl
  b(i1,1)=n;
  b(i1,3)=m;
end

for y1 = 1:m
  for x1 = 1:n
    if l(y1,x1)>0
      lab=l(y1,x1);
      b(lab,5)=b(lab,5)+1;  % Add one to # of pixels	
      b(lab,8)=b(lab,8)+f(y1,x1);

      if x1<b(lab,1)        % Check for min's/max's
        b(lab,1)=x1;
      end
      if x1>b(lab,2)
        b(lab,2)=x1;
      end
      if y1<b(lab,3)
        b(lab,3)=y1;
      end
      if y1>b(lab,4)
	b(lab,4)=y1;
      end
    end
  end
end

for i1 = 1:maxl             % Compute average values
  b(i1,6)=b(i1,2)-b(i1,1)+1;
  b(i1,7)=b(i1,4)-b(i1,3)+1;
  b(i1,8)=round(b(i1,8)/b(i1,5));
  b(i1,9)=round(b(i1,1)+b(i1,2)/2);
  b(i1,10)=round(b(i1,3)+b(i1,4)/2);
 
  % Find Nearest neighbors 


  y2 = b(i1,4);			% Up
  while (y2>0) & (b(i1,13)==0) 
    x2 = b(i1,1);
    while (l(y2,x2) == i1) & (l(y2,x2) == 0) & (x2 <= b(i1,2))
      x2 = x2 + 1;
    end
    if (l(y2,x2) ~= i1) & (l(y2,x2) ~= 0)
      b(i1,13) = l(y2,x2);
    end
    y2 = y2 - 1;
  end

  y2 = b(i1,3);			% Down
  while (y2<m) & (b(i1,14)==0) 
    x2 = b(i1,1);
    while (l(y2,x2) == i1) & (l(y2,x2) == 0) & (x2 <= b(i1,2))
      x2 = x2 + 1;
    end
    if (l(y2,x2) ~= i1) & (l(y2,x2) ~= 0)
      b(i1,14) = l(y2,x2);
    end
    y2 = y2 + 1;
  end

  x2 = b(i1,2);			% Left
  while (x2>0) & (b(i1,11)==0) 
    y2 = b(i1,3);
    while (l(y2,x2) == i1) & (l(y2,x2) == 0) & (y2 <= b(i1,4))
      y2 = y2 + 1;
    end
    if (l(y2,x2) ~= i1) & (l(y2,x2) ~= 0)
      b(i1,11) = l(y2,x2);
    end
    x2 = x2 - 1;
  end

  x2 = b(i1,1);			% Right
  while (x2<n) & (b(i1,12)==0) 
    y2 = b(i1,3);
    while (l(y2,x2) == i1) & (l(y2,x2) == 0) & (y2 <= b(i1,4))
      y2 = y2 + 1;
    end
    if (l(y2,x2) ~= i1) & (l(y2,x2) ~= 0)
      b(i1,12) = l(y2,x2);
    end
    x2 = x2 + 1;
  end

end	
   		       
    
