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:
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:
- The number of positive results in the input image that are defined as such in the ground truth image (TP).
- The number of positive results in the input image that are not defined as such in the ground truth image (FP).
- The number of negative results in the input image that are defined as such in the ground truth image (TN).
- The number of negative results in the input image that are not defined as such in the ground truth image (FN).
- The sensitivity, which measures the proportion of actual positives that are correctly identified as such. This metric is also called recall or true positive rate. $$Sensitivity = Recall = TPR = \frac{TP}{TP+FN}$$
- The specificity, which measures the proportion of actual negatives that are correctly identified as such (true negative rate). $$ Specificity = TNR = \frac{TN}{TN+FP}$$
- The precision, which measures the fraction of relevant results (true positives) among positive results (true and false positives). $$ Precision = \frac{TP}{TP+FP}$$
- The accuracy, which measures the percentage of correct classifications among all results. $$ Accuracy = \frac{TP+TN}{TP+FN+TN+FP} $$
- The Dice coefficient, which is a statistic used for comparing the similarity of two samples (Sørensen-Dice coefficient).This metric is also called $F_1$ score. $$ Dice = F_1 = \frac{2TP}{2TP+FP+FN} $$
- The Jaccard index, also called mean Intersection-Over-Union metric. $$ Jaccard = IoU = \frac{TP}{TP+FP+FN} $$
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 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
inputObjectImage |
The input image. It can be a binary or a label image. | Image | Binary or Label | nullptr | ||||||||
![]() |
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 | ||||||||
![]() |
metricScope |
The type of output measurement to compute.
|
Enumeration | ALL_MODES | |||||||||
![]() |
outputClassMeasurement |
The similarity results. The metrics are given for each label of the input image. | SegmentationMetricsObjectMsr | nullptr | |||||||||
![]() |
outputMicroMeasurement |
The similarity results. The metrics are given globally for the input image. | SegmentationMetricsMicroMsr | nullptr | |||||||||
![]() |
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_object_image |
The input image. It can be a binary or a label image. | image | Binary or Label | None | ||||||||
![]() |
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 | ||||||||
![]() |
metric_scope |
The type of output measurement to compute.
|
enumeration | ALL_MODES | |||||||||
![]() |
output_class_measurement |
The similarity results. The metrics are given for each label of the input image. | SegmentationMetricsObjectMsr | None | |||||||||
![]() |
output_micro_measurement |
The similarity results. The metrics are given globally for the input image. | SegmentationMetricsMicroMsr | None | |||||||||
![]() |
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 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
inputObjectImage |
The input image. It can be a binary or a label image. | Image | Binary or Label | null | ||||||||
![]() |
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 | ||||||||
![]() |
metricScope |
The type of output measurement to compute.
|
Enumeration | ALL_MODES | |||||||||
![]() |
outputClassMeasurement |
The similarity results. The metrics are given for each label of the input image. | SegmentationMetricsObjectMsr | null | |||||||||
![]() |
outputMicroMeasurement |
The similarity results. The metrics are given globally for the input image. | SegmentationMetricsMicroMsr | null | |||||||||
![]() |
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.

