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 and outputImageMeasurement.
// Output structure of the segmentationMetrics function.
struct SegmentationMetricsOutput
{
    /// 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.
    SegmentationMetricsImageMsr::Ptr outputImageMeasurement;
};

// Function prototype
SegmentationMetricsOutput segmentationMetrics( std::shared_ptr< iolink::ImageView > inputObjectImage, std::shared_ptr< iolink::ImageView > inputReferenceImage, SegmentationMetrics::MetricScope metricScope, SegmentationMetricsObjectMsr::Ptr outputClassMeasurement = nullptr, SegmentationMetricsImageMsr::Ptr outputImageMeasurement = nullptr );
This function returns a tuple containing output_class_measurement and output_image_measurement.
// Function prototype.
segmentation_metrics(input_object_image: idt.ImageType,
                     input_reference_image: idt.ImageType,
                     metric_scope: SegmentationMetrics.MetricScope = SegmentationMetrics.MetricScope.BOTH,
                     output_class_measurement: Union[Any, None] = None,
                     output_image_measurement: Union[Any, None] = None) -> Tuple[SegmentationMetricsObjectMsr, SegmentationMetricsImageMsr]
This function returns a SegmentationMetricsOutput structure containing outputClassMeasurement and outputImageMeasurement.
/// 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 SegmentationMetricsImageMsr outputImageMeasurement;
};

// Function prototype.
public static SegmentationMetricsOutput
SegmentationMetrics( IOLink.ImageView inputObjectImage,
                     IOLink.ImageView inputReferenceImage,
                     SegmentationMetrics.MetricScope metricScope = ImageDev.SegmentationMetrics.MetricScope.BOTH,
                     SegmentationMetricsObjectMsr outputClassMeasurement = null,
                     SegmentationMetricsImageMsr outputImageMeasurement = null );

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, Label, Grayscale or Multispectral nullptr
input
metricScope
The type of output measurement to compute.
PER_CLASS The segmentation metrics are only computed for each label of the input images. Only the object measurement output is filled.
PER_IMAGE The segmentation metrics are computed globally on the input images. Only the image measurement output is filled.
BOTH The segmentation metrics are computed globally and for each label of the input images. Both output measurement types are filled.
Enumeration BOTH
output
outputClassMeasurement
The similarity results. The metrics are given for each label of the input image. SegmentationMetricsObjectMsr nullptr
output
outputImageMeasurement
The similarity results. The metrics are given globally for the input image. SegmentationMetricsImageMsr 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, Label, Grayscale or Multispectral None
input
metric_scope
The type of output measurement to compute.
PER_CLASS The segmentation metrics are only computed for each label of the input images. Only the object measurement output is filled.
PER_IMAGE The segmentation metrics are computed globally on the input images. Only the image measurement output is filled.
BOTH The segmentation metrics are computed globally and for each label of the input images. Both output measurement types are filled.
enumeration BOTH
output
output_class_measurement
The similarity results. The metrics are given for each label of the input image. SegmentationMetricsObjectMsr None
output
output_image_measurement
The similarity results. The metrics are given globally for the input image. SegmentationMetricsImageMsr 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, Label, Grayscale or Multispectral null
input
metricScope
The type of output measurement to compute.
PER_CLASS The segmentation metrics are only computed for each label of the input images. Only the object measurement output is filled.
PER_IMAGE The segmentation metrics are computed globally on the input images. Only the image measurement output is filled.
BOTH The segmentation metrics are computed globally and for each label of the input images. Both output measurement types are filled.
Enumeration BOTH
output
outputClassMeasurement
The similarity results. The metrics are given for each label of the input image. SegmentationMetricsObjectMsr null
output
outputImageMeasurement
The similarity results. The metrics are given globally for the input image. SegmentationMetricsImageMsr 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::BOTH );
segmentationMetricsAlgo.execute();

std::cout << "accuracy: " << segmentationMetricsAlgo.outputClassMeasurement()->accuracy( 0 , 0 ) ;
std::cout << "accuracy: " << segmentationMetricsAlgo.outputImageMeasurement()->accuracy( 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.BOTH
segmentation_metrics_algo.execute()

print("accuracy: ", str(segmentation_metrics_algo.output_class_measurement.accuracy(0, 0)))
print("accuracy: ", str(segmentation_metrics_algo.output_image_measurement.accuracy(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.BOTH
};
segmentationMetricsAlgo.Execute();

Console.WriteLine( "accuracy: " + segmentationMetricsAlgo.outputClassMeasurement.accuracy( 0 , 0 ) );
Console.WriteLine( "accuracy: " + segmentationMetricsAlgo.outputImageMeasurement.accuracy( 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::BOTH );

std::cout << "accuracy: " << result.outputClassMeasurement->accuracy( 0 , 0 ) ;
std::cout << "accuracy: " << result.outputImageMeasurement->accuracy( 0 ) ;
polystyrene_sep_label = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep_label.vip"))

result_output_class_measurement, result_output_image_measurement = imagedev.segmentation_metrics(polystyrene_sep_label, polystyrene_sep_label, imagedev.SegmentationMetrics.BOTH)

print("accuracy: ", str(result_output_class_measurement.accuracy(0, 0)))
print("accuracy: ", str(result_output_image_measurement.accuracy(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.BOTH );

Console.WriteLine(  "accuracy: " + result.outputClassMeasurement.accuracy( 0 , 0 )  );
Console.WriteLine(  "accuracy: " + result.outputImageMeasurement.accuracy( 0 )  );





© 2025 Thermo Fisher Scientific Inc. All rights reserved.