ImageDev

Labeling3d

Assigns a same label to each connected component voxel set of a three-dimensional binary or label image.

Access to parameter description

The connected-component labeling algorithm scans the input 3D image from its first to the its XY slice, each slice from its first to its last row along the y-axis, and from its first to its last column along the x-axis. With a standard visualization of a 2D image considering the image origin in the top left corner and the y-axis down, this algorithm scans each XY slice of the input image from top to bottom and left to right.

A connected component refers here to a set of voxels with a same value that are connected or contiguous to each other. They form a region or object within the image. The connectivity between voxels is determined by 6-connectivity, 18-connectivity, or 26-connectivity and can be defined by the neighborhood parameter.

Each pixel of the same connected component (or object) takes the same value, 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.



Figure 1. 3D connected-component labeling: (left) the binary input image, (right) label assignation


A label image pixel may be represented by 8, 16, or 32 bits.
By default, the output image type is defined by the labelType parameter. 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. The processing is then restarted from the beginning to produce the result in the selected new data type. 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. On the contrary, selecting a 32-bit type for an image containing fewer than 256 objects will produce the result in nearly optimal time but will use much more memory than necessary.

See also
See related example

Function Syntax

This function returns outputLabelImage.
// Function prototype
std::shared_ptr< iolink::ImageView > labeling3d( std::shared_ptr< iolink::ImageView > inputObjectImage, Labeling3d::LabelType labelType, Labeling3d::Neighborhood neighborhood, std::shared_ptr< iolink::ImageView > outputLabelImage = nullptr );
This function returns outputLabelImage.
// Function prototype.
labeling_3d(input_object_image: idt.ImageType,
            label_type: Labeling3d.LabelType = Labeling3d.LabelType.LABEL_16_BIT,
            neighborhood: Labeling3d.Neighborhood = Labeling3d.Neighborhood.CONNECTIVITY_26,
            output_label_image: idt.ImageType = None) -> idt.ImageType
This function returns outputLabelImage.
// Function prototype.
public static IOLink.ImageView
Labeling3d( IOLink.ImageView inputObjectImage,
            Labeling3d.LabelType labelType = ImageDev.Labeling3d.LabelType.LABEL_16_BIT,
            Labeling3d.Neighborhood neighborhood = ImageDev.Labeling3d.Neighborhood.CONNECTIVITY_26,
            IOLink.ImageView outputLabelImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputObjectImage
The input binary or label image. Image Binary or Label nullptr
input
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
input
neighborhood
The 3D neighborhood configuration defining the connected components.
CONNECTIVITY_6 Connected components are defined by a 6-neighbor connectivity. The connectivity pattern is composed of voxels sharing a common face with the voxel of interest.
CONNECTIVITY_18 Connected components are defined by a 18-neighbor connectivity. The connectivity pattern is composed of voxels sharing a common edge with the voxel of interest.
CONNECTIVITY_26 Connected components are defined by a 26-neighbor connectivity. The connectivity pattern is a full cube.
Enumeration CONNECTIVITY_26
output
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
input_object_image
The input binary or label image. image Binary or Label None
input
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
input
neighborhood
The 3D neighborhood configuration defining the connected components.
CONNECTIVITY_6 Connected components are defined by a 6-neighbor connectivity. The connectivity pattern is composed of voxels sharing a common face with the voxel of interest.
CONNECTIVITY_18 Connected components are defined by a 18-neighbor connectivity. The connectivity pattern is composed of voxels sharing a common edge with the voxel of interest.
CONNECTIVITY_26 Connected components are defined by a 26-neighbor connectivity. The connectivity pattern is a full cube.
enumeration CONNECTIVITY_26
output
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
input
inputObjectImage
The input binary or label image. Image Binary or Label null
input
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
input
neighborhood
The 3D neighborhood configuration defining the connected components.
CONNECTIVITY_6 Connected components are defined by a 6-neighbor connectivity. The connectivity pattern is composed of voxels sharing a common face with the voxel of interest.
CONNECTIVITY_18 Connected components are defined by a 18-neighbor connectivity. The connectivity pattern is composed of voxels sharing a common edge with the voxel of interest.
CONNECTIVITY_26 Connected components are defined by a 26-neighbor connectivity. The connectivity pattern is a full cube.
Enumeration CONNECTIVITY_26
output
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 null

Object Examples

auto foam_sep = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam_sep.vip" );

Labeling3d labeling3dAlgo;
labeling3dAlgo.setInputObjectImage( foam_sep );
labeling3dAlgo.setLabelType( Labeling3d::LabelType::LABEL_8_BIT );
labeling3dAlgo.setNeighborhood( Labeling3d::Neighborhood::CONNECTIVITY_26 );
labeling3dAlgo.execute();

std::cout << "outputLabelImage:" << labeling3dAlgo.outputLabelImage()->toString();
foam_sep = imagedev.read_vip_image(imagedev_data.get_image_path("foam_sep.vip"))

labeling_3d_algo = imagedev.Labeling3d()
labeling_3d_algo.input_object_image = foam_sep
labeling_3d_algo.label_type = imagedev.Labeling3d.LABEL_8_BIT
labeling_3d_algo.neighborhood = imagedev.Labeling3d.CONNECTIVITY_26
labeling_3d_algo.execute()

print("output_label_image:", str(labeling_3d_algo.output_label_image))
ImageView foam_sep = Data.ReadVipImage( @"Data/images/foam_sep.vip" );

Labeling3d labeling3dAlgo = new Labeling3d
{
    inputObjectImage = foam_sep,
    labelType = Labeling3d.LabelType.LABEL_8_BIT,
    neighborhood = Labeling3d.Neighborhood.CONNECTIVITY_26
};
labeling3dAlgo.Execute();

Console.WriteLine( "outputLabelImage:" + labeling3dAlgo.outputLabelImage.ToString() );

Function Examples

auto foam_sep = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam_sep.vip" );

auto result = labeling3d( foam_sep, Labeling3d::LabelType::LABEL_8_BIT, Labeling3d::Neighborhood::CONNECTIVITY_26 );

std::cout << "outputLabelImage:" << result->toString();
foam_sep = imagedev.read_vip_image(imagedev_data.get_image_path("foam_sep.vip"))

result = imagedev.labeling_3d(foam_sep, imagedev.Labeling3d.LABEL_8_BIT, imagedev.Labeling3d.CONNECTIVITY_26)

print("output_label_image:", str(result))
ImageView foam_sep = Data.ReadVipImage( @"Data/images/foam_sep.vip" );

IOLink.ImageView result = Processing.Labeling3d( foam_sep, Labeling3d.LabelType.LABEL_8_BIT, Labeling3d.Neighborhood.CONNECTIVITY_26 );

Console.WriteLine( "outputLabelImage:" + result.ToString() );





© 2025 Thermo Fisher Scientific Inc. All rights reserved.