ImageDev

SegmentationMetrics

Computes classical quality metrics for assessing the quality of a segmentation relatively to a ground truth.

Access to parameter description

This algorithm allows the comparison of a segmented image with a ground truth in order to assess the accuracy of a segmentation process; for instance, a classification by machine learning.

It outputs several statistical indicators, which can be computed independently for each label of the input images, or globally to provide a unique set of scores: See also

Function Syntax

This function returns a SegmentationMetricsOutput structure containing outputClassMeasurement, outputMicroMeasurement and outputMacroMeasurement.
// Output structure of the segmentationMetrics function.
struct SegmentationMetricsOutput final
{
    /// The similarity results. The metrics are given for each label of the input image.
    SegmentationMetricsObjectMsr::Ptr outputClassMeasurement;
    /// The similarity results. The metrics are given globally for the input image.
    SegmentationMetricsMicroMsr::Ptr outputMicroMeasurement;
    /// The similarity results. The metrics are given globally for the input image by macro-averaging.
    SegmentationMetricsMacroMsr::Ptr outputMacroMeasurement;
};

// Function prototype
SegmentationMetricsOutput segmentationMetrics( std::shared_ptr< iolink::ImageView > inputObjectImage, std::shared_ptr< iolink::ImageView > inputReferenceImage, SegmentationMetrics::MetricScope metricScope );
This function returns a tuple containing output_class_measurement, output_micro_measurement and output_macro_measurement.
// Function prototype.
segmentation_metrics(input_object_image: idt.ImageType,
                     input_reference_image: idt.ImageType,
                     metric_scope: Union[Literal["PER_CLASS"],Literal["MICRO_AVERAGED"],Literal["MACRO_AVERAGED"],Literal["ALL_MODES"],SegmentationMetrics.MetricScope] = SegmentationMetrics.MetricScope.ALL_MODES) -> Tuple[SegmentationMetricsObjectMsr, SegmentationMetricsMicroMsr, SegmentationMetricsMacroMsr]
This function returns a SegmentationMetricsOutput structure containing outputClassMeasurement, outputMicroMeasurement and outputMacroMeasurement.
/// Output structure of the SegmentationMetrics function.
public struct SegmentationMetricsOutput
{
    /// 
    /// The similarity results. The metrics are given for each label of the input image.
    /// 
    public SegmentationMetricsObjectMsr outputClassMeasurement;
    /// The similarity results. The metrics are given globally for the input image.
    public SegmentationMetricsMicroMsr outputMicroMeasurement;
    /// 
    /// The similarity results. The metrics are given globally for the input image by macro-averaging.
    /// 
    public SegmentationMetricsMacroMsr outputMacroMeasurement;
};

// Function prototype.
public static SegmentationMetricsOutput
SegmentationMetrics( IOLink.ImageView inputObjectImage,
                     IOLink.ImageView inputReferenceImage,
                     SegmentationMetrics.MetricScope metricScope = ImageDev.SegmentationMetrics.MetricScope.ALL_MODES );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputObjectImage
The input image. It can be a binary or a label image. Image Binary or Label nullptr
input
inputReferenceImage
The ground truth image. It can be a binary or a label image. It must have same shape and interpretation as the first input image. Image Binary or Label nullptr
input
metricScope
The type of output measurement to compute.
Value Description
PER_CLASS The segmentation metrics are only computed for each label of the input images. Only the object measurement output is filled.
MICRO_AVERAGED The segmentation metrics are computed globally on the input images by macro-averaging. The true positives, false positives, true negatives, and false negatives, scores are aggregated over all classes. The different metrics are deduced from these cumulated scores. Only the image measurement output is filled.
MACRO_AVERAGED The segmentation metrics are computed globally on the input images by macro-averaging. The metric scores are averaged over all classes without being weighted by the probability of presence of each class, except for the accuracy, which is computed identically to the micro-averaged mode. Only the macro measurement output is filled.
ALL_MODES The segmentation metrics are computed globally and for each label of the input images. Both output measurement types are filled.
Enumeration ALL_MODES
output
outputClassMeasurement
The similarity results. The metrics are given for each label of the input image. SegmentationMetricsObjectMsr nullptr
output
outputMicroMeasurement
The similarity results. The metrics are given globally for the input image. SegmentationMetricsMicroMsr nullptr
output
outputMacroMeasurement
The similarity results. The metrics are given globally for the input image by macro-averaging. SegmentationMetricsMacroMsr nullptr
Parameter Name Description Type Supported Values Default Value
input
input_object_image
The input image. It can be a binary or a label image. image Binary or Label None
input
input_reference_image
The ground truth image. It can be a binary or a label image. It must have same shape and interpretation as the first input image. image Binary or Label None
input
metric_scope
The type of output measurement to compute.
Value Description
PER_CLASS The segmentation metrics are only computed for each label of the input images. Only the object measurement output is filled.
MICRO_AVERAGED The segmentation metrics are computed globally on the input images by macro-averaging. The true positives, false positives, true negatives, and false negatives, scores are aggregated over all classes. The different metrics are deduced from these cumulated scores. Only the image measurement output is filled.
MACRO_AVERAGED The segmentation metrics are computed globally on the input images by macro-averaging. The metric scores are averaged over all classes without being weighted by the probability of presence of each class, except for the accuracy, which is computed identically to the micro-averaged mode. Only the macro measurement output is filled.
ALL_MODES The segmentation metrics are computed globally and for each label of the input images. Both output measurement types are filled.
enumeration ALL_MODES
output
output_class_measurement
The similarity results. The metrics are given for each label of the input image. SegmentationMetricsObjectMsr None
output
output_micro_measurement
The similarity results. The metrics are given globally for the input image. SegmentationMetricsMicroMsr None
output
output_macro_measurement
The similarity results. The metrics are given globally for the input image by macro-averaging. SegmentationMetricsMacroMsr None
Parameter Name Description Type Supported Values Default Value
input
inputObjectImage
The input image. It can be a binary or a label image. Image Binary or Label null
input
inputReferenceImage
The ground truth image. It can be a binary or a label image. It must have same shape and interpretation as the first input image. Image Binary or Label null
input
metricScope
The type of output measurement to compute.
Value Description
PER_CLASS The segmentation metrics are only computed for each label of the input images. Only the object measurement output is filled.
MICRO_AVERAGED The segmentation metrics are computed globally on the input images by macro-averaging. The true positives, false positives, true negatives, and false negatives, scores are aggregated over all classes. The different metrics are deduced from these cumulated scores. Only the image measurement output is filled.
MACRO_AVERAGED The segmentation metrics are computed globally on the input images by macro-averaging. The metric scores are averaged over all classes without being weighted by the probability of presence of each class, except for the accuracy, which is computed identically to the micro-averaged mode. Only the macro measurement output is filled.
ALL_MODES The segmentation metrics are computed globally and for each label of the input images. Both output measurement types are filled.
Enumeration ALL_MODES
output
outputClassMeasurement
The similarity results. The metrics are given for each label of the input image. SegmentationMetricsObjectMsr null
output
outputMicroMeasurement
The similarity results. The metrics are given globally for the input image. SegmentationMetricsMicroMsr null
output
outputMacroMeasurement
The similarity results. The metrics are given globally for the input image by macro-averaging. SegmentationMetricsMacroMsr null

Object Examples

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

SegmentationMetrics segmentationMetricsAlgo;
segmentationMetricsAlgo.setInputObjectImage( polystyrene_sep_label );
segmentationMetricsAlgo.setInputReferenceImage( polystyrene_sep_label );
segmentationMetricsAlgo.setMetricScope( SegmentationMetrics::MetricScope::ALL_MODES );
segmentationMetricsAlgo.execute();

std::cout << "labelValue: " << segmentationMetricsAlgo.outputClassMeasurement()->labelValue( 0 , 0 ) ;
std::cout << "truePositive: " << segmentationMetricsAlgo.outputMicroMeasurement()->truePositive( 0 ) ;
std::cout << "sensitivity: " << segmentationMetricsAlgo.outputMacroMeasurement()->sensitivity( 0 ) ;
polystyrene_sep_label = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep_label.vip"))

segmentation_metrics_algo = imagedev.SegmentationMetrics()
segmentation_metrics_algo.input_object_image = polystyrene_sep_label
segmentation_metrics_algo.input_reference_image = polystyrene_sep_label
segmentation_metrics_algo.metric_scope = imagedev.SegmentationMetrics.ALL_MODES
segmentation_metrics_algo.execute()

print("labelValue: ", str(segmentation_metrics_algo.output_class_measurement.label_value(0, 0)))
print("truePositive: ", str(segmentation_metrics_algo.output_micro_measurement.true_positive(0)))
print("sensitivity: ", str(segmentation_metrics_algo.output_macro_measurement.sensitivity(0)))
ImageView polystyrene_sep_label = Data.ReadVipImage( @"Data/images/polystyrene_sep_label.vip" );

SegmentationMetrics segmentationMetricsAlgo = new SegmentationMetrics
{
    inputObjectImage = polystyrene_sep_label,
    inputReferenceImage = polystyrene_sep_label,
    metricScope = SegmentationMetrics.MetricScope.ALL_MODES
};
segmentationMetricsAlgo.Execute();

Console.WriteLine( "labelValue: " + segmentationMetricsAlgo.outputClassMeasurement.labelValue( 0 , 0 ) );
Console.WriteLine( "truePositive: " + segmentationMetricsAlgo.outputMicroMeasurement.truePositive( 0 ) );
Console.WriteLine( "sensitivity: " + segmentationMetricsAlgo.outputMacroMeasurement.sensitivity( 0 ) );

Function Examples

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

auto result = segmentationMetrics( polystyrene_sep_label, polystyrene_sep_label, SegmentationMetrics::MetricScope::ALL_MODES );

std::cout << "labelValue: " << result.outputClassMeasurement->labelValue( 0 , 0 ) ;
std::cout << "truePositive: " << result.outputMicroMeasurement->truePositive( 0 ) ;
std::cout << "sensitivity: " << result.outputMacroMeasurement->sensitivity( 0 ) ;
polystyrene_sep_label = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep_label.vip"))

result_output_class_measurement, result_output_micro_measurement, result_output_macro_measurement = imagedev.segmentation_metrics(polystyrene_sep_label, polystyrene_sep_label, imagedev.SegmentationMetrics.ALL_MODES)

print("labelValue: ", str(result_output_class_measurement.label_value(0, 0)))
print("truePositive: ", str(result_output_micro_measurement.true_positive(0)))
print("sensitivity: ", str(result_output_macro_measurement.sensitivity(0)))
ImageView polystyrene_sep_label = Data.ReadVipImage( @"Data/images/polystyrene_sep_label.vip" );

Processing.SegmentationMetricsOutput result = Processing.SegmentationMetrics( polystyrene_sep_label, polystyrene_sep_label, SegmentationMetrics.MetricScope.ALL_MODES );

Console.WriteLine(  "labelValue: " + result.outputClassMeasurement.labelValue( 0 , 0 )  );
Console.WriteLine(  "truePositive: " + result.outputMicroMeasurement.truePositive( 0 )  );
Console.WriteLine(  "sensitivity: " + result.outputMacroMeasurement.sensitivity( 0 )  );



© 2026 Thermo Fisher Scientific Inc. All rights reserved.