L = labelmatrix(CC)
creates a label matrix, L, from the connected components
structure CC returned by bwconncomp.
labelmatrix is more memory efficient than bwlabel and bwlabeln because it returns its
label matrix in the smallest numeric class necessary for the number of
objects.
Calculate the connected components using bwconncomp.
CC = bwconncomp(BW);
Create a label matrix using labelmatrix.
L = labelmatrix(CC);
For comparison, create a second label matrix using bwlabel.
L2 = bwlabel(BW);
View both label matrices in the workspace. Note that labelmatrix uses the smallest numeric class necessary for the number of objects and therefore is more memory efficient than bwlabel .
whos LL2
Name Size Bytes Class Attributes
L 256x256 65536 uint8
L2 256x256 524288 double
Display the label matrix as an RGB image using label2rgb. To make it easier to differentiate the different connected components, shuffle the color order of the labels.
Label matrix of contiguous regions, returned as matrix of nonnegative
integers. The pixels labeled 0 are the background. The
pixels labeled 1 make up one object; the pixels labeled
2 make up a second object; and so on.
The size of L is CC.ImageSize. The
class of L depends on CC.NumObjects,
as shown in the table.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.