Label

Label connected components in binary images

Library

Morphological Operations

visionmorphops

Description

The Label block labels the objects in a binary image, BW. The
background is represented by pixels equal to 0 (black) and objects
are represented by pixels equal to 1 (white). At the Label port,
the block outputs a label matrix that is the same size as the input
matrix. In the label matrix, pixels equal to 0 represent the background,
pixels equal to 1 represent the first object, pixels equal to 2 represent
the second object, and so on. At the Count port, the block outputs
a scalar value that represents the number of labeled objects.

Port

Input/Output

Supported Data Types

Complex Values Supported

BW

Vector or matrix that represents a binary image

Boolean

No

Label

Label matrix

8-, 16-, and 32-bit unsigned integer

No

Count

Scalar that represents the number of labeled objects

Same as Label port

No

Use the Connectivity parameter to define which pixels are connected to
each other. If you want a pixel to be connected to the other pixels located on the top,
bottom, left, and right, select 4. If you want a pixel to be
connected to the other pixels on the top, bottom, left, right, and diagonally, select
8.

Consider the following 3-by-3 image. If, for the Connectivity parameter,
you select 4, the block considers the white pixels marked by
black circles to be connected.

If, for the Connectivity parameter, you select
8, the block considers the white pixels marked by black
circles to be connected.

Use the Output parameter to determine the block's output. If you select
Label matrix and number of labels, ports Label and Count
appear on the block. The block outputs the label matrix at the Label port and the number
of labeled objects at the Count port. If you select Label
matrix, the Label port appears on the block. If you select
Number of labels, the Count port appears on the
block.

Use the Output data type parameter to set the data type of the outputs at
the Label and Count ports. If you select Automatic, the block
calculates the maximum number of objects that can fit inside the image based on the
image size and the connectivity you specified. Based on this calculation, it determines
the minimum output data type size that guarantees unique region labels and sets the
output data type appropriately. If you select uint32,
uint16, or uint8, the data
type of the output is 32-, 16-, or 8-bit unsigned integers, respectively. If you select
uint16, or uint8, the
If label exceeds data type size, mark remaining regions using
parameter appears in the dialog box. If the number of found objects exceeds the maximum
number that can be represented by the output data type, use this parameter to specify
the block's behavior. If you select maximum value of the output data
type, the remaining regions are labeled with the maximum value of the
output data type. If you select zero, the remaining regions
are labeled with zeroes.

Parameters

Connectivity

Specify which pixels are connected to each other. If you want a pixel to
be connected to the pixels on the top, bottom, left, and right, select
4. If you want a pixel to be connected to the
pixels on the top, bottom, left, right, and diagonally, select
8.

Output

Determine the block's output. If you select Label matrix and
number of labels, the Label and Count ports appear on the
block. The block outputs the label matrix at the Label port and the number
of labeled objects at the Count port. If you select Label
matrix, the Label port appears on the block. If you select
Number of labels, the Count port appears on
the block.

Output
data type

Set the data type of the outputs at the Label and Count ports. If you
select Automatic, the block determines the
appropriate data type for the output. If you select
uint32, uint16, or
uint8, the data type of the output is 32-,
16-, or 8-bit unsigned integers, respectively.

If
label exceeds data type size, mark remaining regions using

Use this parameter to specify the block's behavior if the number of found
objects exceeds the maximum number that can be represented by the output
data type. If you select maximum value of the output data
type, the remaining regions are labeled with the maximum
value of the output data type. If you select
zero, the remaining regions are labeled with
zeroes. This parameter is visible if, for the Output data
type parameter, you choose uint16
or uint8.