| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Image Processing Toolbox |
| Contents | Index |
| Learn more about Image Processing Toolbox |
L = labelmatrix(CC)
L = labelmatrix(CC) creates a label matrix from the connected components structure CC returned by bwconncomp. The size of L is CC.ImageSize. The elements of L are integer values greater than or equal to 0. 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 class of L depends on CC.NumObjects, as shown in the following table.
| Class | Range |
|---|---|
| 'uint8' | CC.NumObjects
|
| 'uint16' | 256
|
| 'uint32' | 65536
|
| 'double' | CC.NumObjects
|
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.
CC is a structure returned by bwconncomp. The label matrix L is uint8, uint16, uint32, or double.
Calculate the connected components and display results:
BW = imread('text.png');
CC = bwconncomp(BW);
L = labelmatrix(CC);
L2 = bwlabel(BW);
whos L L2
The output for whos appears as follows:
Name Size Bytes Class Attributes L 256x256 65536 uint8 L2 256x256 524288 double
figure, imshow(label2rgb(L));
The output for imshow appears as follows:

bwconncomp, bwlabel, bwlabeln, label2rgb, and regionprops
![]() | label2rgb | makecform | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |