Label and count the connected regions in a binary image
The ConnectedComponentLabeler object labels and counts the connected regions in a binary image. The System object can output a label matrix, where 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. The object can also output a scalar that represents the number of labeled objects.
H = vision.ConnectedComponentLabeler returns a System object, H, that labels and counts connected regions in a binary image.
H = vision.ConnectedComponentLabeler(Name,Value) returns a label System object, H, with each property set to the specified value. You can specify additional name-value pair arguments in any order as (Name1, Value1,...,NameN,ValueN).
Which pixels are connected to each other
Specify which pixels are connected to each other as either 4 or 8. If a pixel should be connected to the pixels on the top, bottom, left, and right, set this property to 4. If a pixel should be connected to the pixels on the top, bottom, left, right, and diagonally, set this property to 8. The default is 8.
Enable output of label matrix
Enable output of number of labels
Output data type
Set the data type of the output to one of Automatic, uint32 , uint16, uint8. If this property is set to Automatic, the System object determines the appropriate data type for the output. If it is set to uint32, uint16, or uint8, the data type of the output is 32-, 16-, or 8-bit unsigned integers, respectively. The default is Automatic.
Behavior if number of found objects exceeds data type size of output
Specify the System object's behavior if the number of found objects exceeds the maximum number that can be represented by the output data type as Use maximum value of the output data type, or Use zero . If this property is set to Use maximum value of the output data type, the remaining regions are labeled with the maximum value of the output data type. If this property is set to Use zero, the remaining regions are labeled with zeroes. This property applies when you set the OutputDataType property to uint16 or uint8. The default is Use maximum value of the output data type.
|clone||Create connected component labeler object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs from step method|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|step||Label and count connected regions in input|
Label connected regions in an image.
img = logical([0 0 0 0 0 0 0 0 0 0 0 0 0; ... 0 1 1 1 1 0 0 0 0 0 0 1 0; ... 0 1 1 1 1 1 0 0 0 0 1 1 0; ... 0 1 1 1 1 1 0 0 0 1 1 1 0; ... 0 1 1 1 1 0 0 0 1 1 1 1 0; ... 0 0 0 0 0 0 0 1 1 1 1 1 0; ... 0 0 0 0 0 0 0 0 0 0 0 0 0]) hlabel = vision.ConnectedComponentLabeler; hlabel.LabelMatrixOutputPort = true; hlabel.LabelCountOutputPort = false; labeled = step(hlabel, img)
This object implements the algorithm, inputs, and outputs described on the Label block reference page. The object properties correspond to the block parameters, except:
The LabelCountOutputPort and LabelMatrixOutputPort object properties correspond to the Output block parameter.