ImageDev

ObjectCount

Computes the number of objects in a binary or label image.

Access to parameter description

For an introduction: section Image Analysis.
If the input is a binary image, it is first labeled by connected component and the maximum label value is returned as number of objects. If the input is a label image, the number of objects is equal to the maximum grey level value of the input image.

See also
See related examples

Function Syntax

This function returns a ObjectCountOutput structure containing the outputLabelImage and outputMeasurement output parameters.
// Output structure.
struct ObjectCountOutput
{
    std::shared_ptr< iolink::ImageView > outputLabelImage;
    ObjectCountMsr::Ptr outputMeasurement;
};

// Function prototype.
ObjectCountOutput
objectCount( std::shared_ptr< iolink::ImageView > inputObjectImage,
             std::shared_ptr< iolink::ImageView > outputLabelImage = NULL,
             ObjectCountMsr::Ptr outputMeasurement = NULL );
This function returns a tuple containing the output_label_image and output_measurement output parameters.
// Function prototype.
object_count( input_object_image, output_label_image = None, output_measurement = None )
This function returns a ObjectCountOutput structure containing the outputLabelImage and outputMeasurement output parameters.
/// Output structure of the ObjectCount function.
public struct ObjectCountOutput
{
    public IOLink.ImageView outputLabelImage;
    public ObjectCountMsr outputMeasurement;
};

// Function prototype.
public static ObjectCountOutput
ObjectCount( IOLink.ImageView inputObjectImage,
             IOLink.ImageView outputLabelImage = null,
             ObjectCountMsr outputMeasurement = null );

Class Syntax

Parameters

Class Name ObjectCount

Parameter Name Description Type Supported Values Default Value
input
inputObjectImage
The binary or label input image. Image Binary or Label nullptr
output
outputLabelImage
The label output image. Image nullptr
output
outputMeasurement
The output measurement result. ObjectCountMsr nullptr

Object Examples

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

ObjectCount objectCountAlgo;
objectCountAlgo.setInputObjectImage( polystyrene_sep_label );
objectCountAlgo.execute();

std::cout << "outputLabelImage:" << objectCountAlgo.outputLabelImage()->toString();
std::cout << "count: " << objectCountAlgo.outputMeasurement()->count( 0 ) ;
polystyrene_sep_label = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep_label.vip"))

object_count_algo = imagedev.ObjectCount()
object_count_algo.input_object_image = polystyrene_sep_label
object_count_algo.execute()

print( "output_label_image:", str( object_count_algo.output_label_image ) )
print( "count: ", str( object_count_algo.output_measurement.count( 0 ) ) )
ImageView polystyrene_sep_label = Data.ReadVipImage( @"Data/images/polystyrene_sep_label.vip" );

ObjectCount objectCountAlgo = new ObjectCount
{
    inputObjectImage = polystyrene_sep_label
};
objectCountAlgo.Execute();

Console.WriteLine( "outputLabelImage:" + objectCountAlgo.outputLabelImage.ToString() );
Console.WriteLine( "count: " + objectCountAlgo.outputMeasurement.count( 0 ) );

Function Examples

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

auto result = objectCount( polystyrene_sep_label );

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

result_output_label_image, result_output_measurement = imagedev.object_count( polystyrene_sep_label )

print( "output_label_image:", str( result_output_label_image ) )
print( "count: ", str( result_output_measurement.count( 0 ) )  )
ImageView polystyrene_sep_label = Data.ReadVipImage( @"Data/images/polystyrene_sep_label.vip" );

Processing.ObjectCountOutput result = Processing.ObjectCount( polystyrene_sep_label );

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