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 outputLabelImage and outputMeasurement.
// Output structure of the objectCount function.
struct ObjectCountOutput
{
    /// The label output image.
    std::shared_ptr< iolink::ImageView > outputLabelImage;
    /// The output measurement result.
    ObjectCountMsr::Ptr outputMeasurement;
};

// Function prototype
ObjectCountOutput objectCount( std::shared_ptr< iolink::ImageView > inputObjectImage, std::shared_ptr< iolink::ImageView > outputLabelImage = nullptr, ObjectCountMsr::Ptr outputMeasurement = nullptr );
This function returns a tuple containing output_label_image and output_measurement.
// Function prototype.
object_count(input_object_image: idt.ImageType,
             output_label_image: idt.ImageType = None,
             output_measurement: Union[Any, None] = None) -> Tuple[idt.ImageType, ObjectCountMsr]
This function returns a ObjectCountOutput structure containing outputLabelImage and outputMeasurement.
/// Output structure of the ObjectCount function.
public struct ObjectCountOutput
{
    /// The label output image.
    public IOLink.ImageView outputLabelImage;
    /// The output measurement result.
    public ObjectCountMsr outputMeasurement;
};

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

Class Syntax

Parameters

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
Parameter Name Description Type Supported Values Default Value
input
input_object_image
The binary or label input image. image Binary or Label None
output
output_label_image
The label output image. image None
output
output_measurement
The output measurement result. ObjectCountMsr None
Parameter Name Description Type Supported Values Default Value
input
inputObjectImage
The binary or label input image. Image Binary or Label null
output
outputLabelImage
The label output image. Image null
output
outputMeasurement
The output measurement result. ObjectCountMsr null

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