[Top] [Up] [Prev] [Next] [Up] [Basic Concepts] [Demonstrations] [Functions] SDC Morphology Toolbox V1.1 15Jan02

mmlabel - Label a binary image.


Synopsis
y = mmlabel( f, Bc )
Input
f: Binary image (logical uint8).
Bc: Structuring element. ( connectivity). Default: Elementary cross (mmsecross).
Output
y: Gray-scale (uint8 or uint16) or binary image (logical uint8). (uint16)
Description
mmlabel creates the image y by labeling the connect components of a binary image f, according to the connectivity defined by the structuring element Bc. The background pixels (with value 0) are not labeled. The maximum label value in the output image gives the number of its connected components.
Examples

Numerical Example

f=mmbinary(uint8([0 1 0 1 1; 1 0 0 1 0]))

f =
     0     1     0     1     1
     1     0     0     1     0
g=mmlabel(f)

g =
     0     2     0     3     3
     1     0     0     3     0

Image Example

The maximum label value gives the number of connected blobs in the image.

f = mmreadgray('blob3.tif');
g=mmlabel(f);
nblobs=mmstats(g,'max')

nblobs =
    18
mmshow(f);
mmlblshow(g);
image
(f)
image
(g)
Equation

equation

Where H is the number of image rows, and y1 and y2 are the row and column coordinates respectively.
Algorithm
function y = mmlabeleq(f, Bc)
faux=f;
fmark=mmsubm(f,f);             % zero image
r=fmark;
label=1;
y=mmgray(f,'uint16',0);        % zero image (output)
while ~mmisequal(faux,logical(uint8(0)))
   x=find(faux);               %get all unlabeled pixel
   fmark(x(1))=1;              %get the first unlabeled pixel
   r=mminfrec(fmark,faux,Bc);  %detects all pixels connected to it
   faux=mmsubm(faux,r);        %remove them from faux
   r=mmgray(r,'uint16',label); %label them with the value label
   y=mmunion(y,r);             %merge them with the labeled image
   label=label+1;
end
See Also
mmareaopen - Area opening.
mmblob - Blob measurements from a labeled image.
mmfreedom - Control automatic data type conversion.
mmgrain - Gray-scale statistics for each labeled region.
mmlabelflat - Label the flat zones of gray-scale images.
mmsebox - Create a box structuring element.
mmsecross - Cross structuring element.

[Top] [Up] [Prev] [Next] [Up] [Basic Concepts] [Demonstrations] [Functions] Valid XHTML 1.0!
Copyright (c) 1998-2002 by SDC Information Systems