This algorithm scans the input image from top to bottom and left to right.
Each pixel of the same connected component (or object) takes the same value, and each object is assigned
to a different value, starting from value 1. The assigned gray level (or label) depends on the location of
the object in the image. The maximum gray level value gives the total number of objects in the original
binary or label image, which means that all objects have consecutive indices.
A label image may be 8, 16 or 32 bits per pixel.
By default the output image type is defined by the labelType parameter, but if the number of labels
exceeds its capacity, then the output image is automatically converted to the upper type to be able to manage
the number of labels. To optimize the computation, it is important to select a relevant type for
the output. Selecting an 8-bit type for an image containing more than 65535 objects will produce the expected
result, but will compute it in much more time than by selecting a 32-bit output type directly.
The type of connectivity to define the connected components is managed by the neighborhood parameter.
// Function prototype.publicstaticIOLink.ImageViewLabeling2d(IOLink.ImageView inputObjectImage,Labeling2d.LabelType labelType =ImageDev.Labeling2d.LabelType.LABEL_16_BIT,Labeling2d.Neighborhood neighborhood =ImageDev.Labeling2d.Neighborhood.CONNECTIVITY_8,IOLink.ImageView outputLabelImage =null);
Class Syntax
// Command constructor.Labeling2d();/// Gets the inputObjectImage parameter./// The input binary or label image.
std::shared_ptr< iolink::ImageView> inputObjectImage()const;/// Sets the inputObjectImage parameter./// The input binary or label image.void setInputObjectImage( std::shared_ptr< iolink::ImageView> inputObjectImage );/// Gets the labelType parameter./// The minimum output data type. Automatically changed if not sufficient to encode all labels.Labeling2d::LabelType labelType()const;/// Sets the labelType parameter./// The minimum output data type. Automatically changed if not sufficient to encode all labels.void setLabelType(constLabeling2d::LabelType& labelType );/// Gets the neighborhood parameter./// The 2D neighborhood configuration defining the connected components.Labeling2d::Neighborhood neighborhood()const;/// Sets the neighborhood parameter./// The 2D neighborhood configuration defining the connected components.void setNeighborhood(constLabeling2d::Neighborhood& neighborhood );/// Gets the outputLabelImage parameter./// The output label image. Its dimensions are forced to the same values as the input image. Its type depends on the number of objects and the labelType parameter.
std::shared_ptr< iolink::ImageView> outputLabelImage()const;/// Sets the outputLabelImage parameter./// The output label image. Its dimensions are forced to the same values as the input image. Its type depends on the number of objects and the labelType parameter.void setOutputLabelImage( std::shared_ptr< iolink::ImageView> outputLabelImage );// Method to launch the command.void execute();
# Property of the inputObjectImage parameter.Labeling2d.input_object_image
# Property of the labelType parameter.Labeling2d.label_type
# Property of the neighborhood parameter.Labeling2d.neighborhood
# Property of the outputLabelImage parameter.Labeling2d.output_label_image
// Method to launch the command.
execute()
// Command constructor.Labeling2d()// Property of the inputObjectImage parameter.Labeling2d.inputObjectImage
// Property of the labelType parameter.Labeling2d.labelType
// Property of the neighborhood parameter.Labeling2d.neighborhood
// Property of the outputLabelImage parameter.Labeling2d.outputLabelImage
// Method to launch the command.Execute()
Parameters
Parameter Name
Description
Type
Supported Values
Default Value
inputObjectImage
The input binary or label image.
Image
Binary or Label
nullptr
labelType
The minimum output data type. Automatically changed if not sufficient to encode all labels.
LABEL_8_BIT
The minimum output data type is 8-bit per pixel.
LABEL_16_BIT
The minimum output data type is 16-bit per pixel.
LABEL_32_BIT
The minimum output data type is 32-bit per pixel.
Enumeration
LABEL_16_BIT
neighborhood
The 2D neighborhood configuration defining the connected components.
CONNECTIVITY_4
Connected components are defined by a 4-neighbor connectivity. The connectivity pattern is a cross.
CONNECTIVITY_8
Connected components are defined by a 8-neighbor connectivity. The connectivity pattern is a square.
Enumeration
CONNECTIVITY_8
outputLabelImage
The output label image. Its dimensions are forced to the same values as the input image. Its type depends on the number of objects and the labelType parameter.
Image
nullptr
Parameter Name
Description
Type
Supported Values
Default Value
input_object_image
The input binary or label image.
image
Binary or Label
None
label_type
The minimum output data type. Automatically changed if not sufficient to encode all labels.
LABEL_8_BIT
The minimum output data type is 8-bit per pixel.
LABEL_16_BIT
The minimum output data type is 16-bit per pixel.
LABEL_32_BIT
The minimum output data type is 32-bit per pixel.
enumeration
LABEL_16_BIT
neighborhood
The 2D neighborhood configuration defining the connected components.
CONNECTIVITY_4
Connected components are defined by a 4-neighbor connectivity. The connectivity pattern is a cross.
CONNECTIVITY_8
Connected components are defined by a 8-neighbor connectivity. The connectivity pattern is a square.
enumeration
CONNECTIVITY_8
output_label_image
The output label image. Its dimensions are forced to the same values as the input image. Its type depends on the number of objects and the labelType parameter.
image
None
Parameter Name
Description
Type
Supported Values
Default Value
inputObjectImage
The input binary or label image.
Image
Binary or Label
null
labelType
The minimum output data type. Automatically changed if not sufficient to encode all labels.
LABEL_8_BIT
The minimum output data type is 8-bit per pixel.
LABEL_16_BIT
The minimum output data type is 16-bit per pixel.
LABEL_32_BIT
The minimum output data type is 32-bit per pixel.
Enumeration
LABEL_16_BIT
neighborhood
The 2D neighborhood configuration defining the connected components.
CONNECTIVITY_4
Connected components are defined by a 4-neighbor connectivity. The connectivity pattern is a cross.
CONNECTIVITY_8
Connected components are defined by a 8-neighbor connectivity. The connectivity pattern is a square.
Enumeration
CONNECTIVITY_8
outputLabelImage
The output label image. Its dimensions are forced to the same values as the input image. Its type depends on the number of objects and the labelType parameter.