Label foreground objects in the n-dimensional binary image bw.
The optional argument n sets the connectivity and defaults 26, for 26-connectivity in 3-D images. Other possible values are 18 and 6 for 3-D images, 4 and 8 for 2-D images, or an arbitrary N-dimensional binary connectivity mask where each dimension is of size 3.
The output l is an Nd-array where 0 indicates a background pixel, 1 indicates that the pixel belongs to object number 1, 2 that the pixel belongs to object number 2, etc. The total number of objects is num.
The algorithm used is a disjoint-set data structure, a.k.a. union-find. See, for example, http://en.wikipedia.org/wiki/Union-find
See also: bwconncomp, bwlabel, regionprops.
Package: image