segmetrics.measure

class segmetrics.measure.AsymmetricMeasureMixin(*args, **kwargs)

Bases: MeasureProtocol

Defines an asymmetric performance measure.

Symmetric performance measures are guaranteed to yield the same results when the actual and the expected segmentation masks are swapped. Asymmetric performance measures can yield different results when the results are swapped.

reversed(**kwargs) Measure

Returns a measure for comparing the underlying asymmetric performance measure measure in the opposite direction (i.e. swapping the actual and the expected segmentation masks).

Keyword arguments are passed through to ReverseMeasureAdapter.

Returns:

This measure decorated by ReverseMeasureAdapter.

symmetric(**kwargs) Measure

Returns a bidirectional variant of the underlying asymmetric performance measure. The underlying performance measure is used for computation of performance values in both direction (i.e. with the original segmentation masks, and, in addition, with actual and expected segmentation masks swapped).

Keyword arguments are passed through to SymmetricMeasureAdapter.

Returns:

This measure decorated by SymmetricMeasureAdapter.

class segmetrics.measure.ImageMeasureMixin(*args, correspondance_function: Literal['min', 'max'], **kwargs)

Bases: MeasureProtocol

Defines an image-level performance measure.

The computation of such measures only regards the union of the individual objects, not the individual objects themselves.

Parameters:

correspondance_function – Determines how the object correspondances between the segmented and the ground truth objects are determined when using the object_based() method. The correspondances are established by choosing the segmented object for each ground truth object, for which the obtained scores are either minimal (min) or maximal (max).

object_based(**kwargs) Measure

Returns measure for comparing the individual objects (as opposed to only considering the union thereof).

Keyword arguments are passed through to ObjectMeasureAdapter.

Returns:

This measure decorated by ObjectMeasureAdapter.

class segmetrics.measure.Measure(aggregation: Literal['sum', 'mean', 'geometric-mean', 'object-mean'] = 'mean')

Bases: MeasureProtocol

Defines a performance measure.

Parameters:

aggregation – Controls whether the results of this performance measure are aggregated by summation (sum), by averaging (mean), by using the geometric mean (geometric-mean), or by computing the proportion with respect to the number of annotated objects (object-mean).

property aggregation: Literal['sum', 'mean', 'geometric-mean', 'object-mean']

Indicates whether the results of this performance measure are aggregated by summation (sum), by averaging (mean), by using the geometric mean (geometric-mean), or by computing the proportion with respect to the number of annotated objects (object-mean).

compute(actual: None) List[float]

Computes the performance measure for the given segmentation results based on the previously set expected result.

Parameters:

actual – An image containing uniquely labeled object masks corresponding to the segmentation results.

default_name() str

Returns the default name of this measure.

set_expected(expected: None) None

Sets the expected result for evaluation.

Parameters:

expected – An image containing uniquely labeled object masks corresponding to the ground truth.

class segmetrics.measure.MeasureProtocol(*args, **kwargs)

Bases: Protocol

Type protocol of performance measures.

property aggregation: Literal['sum', 'mean', 'geometric-mean', 'object-mean']

Indicates whether the results of this performance measure are aggregated by summation (sum), by averaging (mean), by using the geometric mean (geometric-mean), or by computing the proportion with respect to the number of annotated objects (object-mean).

compute(actual: None) List[float]

Computes the performance measure for the given segmentation results based on the previously set expected result.

Parameters:

actual – An image containing uniquely labeled object masks corresponding to the segmentation results.

default_name() str

Returns the default name of this measure.

set_expected(expected: None) None

Sets the expected result for evaluation.

Parameters:

expected – An image containing uniquely labeled object masks corresponding to the ground truth.

class segmetrics.measure.ObjectMeasureAdapter(measure: MeasureProtocol, correspondance_function: Callable[[List[float]], float], **kwargs)

Bases: AsymmetricMeasureMixin, Measure

Adapter to use image-level measures on a per-object level.

Computes the underlying image-level measure on a per-object level. Object correspondances between the segmented and the ground truth objects are established by choosing the segmented object for each ground truth object, for which the obtained scores are either minimal or maximal.

Parameters:
  • measure – The underlying image-level measure.

  • correspondance_function – Determines the object correspondances by reducing a sequence of scores to a single score value.

compute(actual: None) List[float]

Computes the performance measure for the given segmentation results based on the previously set expected result.

Parameters:

actual – An image containing uniquely labeled object masks corresponding to the segmentation results.

default_name()

Returns the default name of this measure.

class segmetrics.measure.ReverseMeasureAdapter(measure: MeasureProtocol, **kwargs)

Bases: Measure

compute(actual: None) List[float]

Computes the performance measure for the given segmentation results based on the previously set expected result.

Parameters:

actual – An image containing uniquely labeled object masks corresponding to the segmentation results.

default_name() str

Returns the default name of this measure.

class segmetrics.measure.SymmetricMeasureAdapter(measure1: MeasureProtocol, measure2: MeasureProtocol, **kwargs)

Bases: Measure

compute(actual: None) List[float]

Computes the performance measure for the given segmentation results based on the previously set expected result.

Parameters:

actual – An image containing uniquely labeled object masks corresponding to the segmentation results.

default_name() str

Returns the default name of this measure.

set_expected(expected: None) None

Sets the expected result for evaluation.

Parameters:

expected – An image containing uniquely labeled object masks corresponding to the ground truth.