ImageDev

Labeling3d

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

Access to parameter description

This algorithm scans the input 3D image from the first to the last XY slice and each slice from top to bottom and left to right.
Each voxel 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.

See also

Function Syntax

This function returns the outputLabelImage output parameter.
// 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 = NULL );
This function returns the outputLabelImage output parameter.
// Function prototype.
labeling_3d( input_object_image,
             label_type = Labeling3d.LabelType.LABEL_16_BIT,
             neighborhood = Labeling3d.Neighborhood.CONNECTIVITY_26,
             output_label_image = None )
This function returns the outputLabelImage output parameter.
// 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

Class Name Labeling3d

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

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() );