segmentationmetrics package

Subpackages

Submodules

segmentationmetrics.metrics module

class segmentationmetrics.metrics.SegmentationMetrics(prediction, truth, zoom, percentile=95, symmetric=True, many_labels=False)[source]

Bases: object

dice

Dice similarity score. The dice score is a measure of the overlap between the predicted and true masks. It is calculated as 2*TP / (2*TP + FP + FN). If there are multiple labels, the dice score is the mean of the dice scores for each label.

Type:

float

jaccard

Jaccard similarity score. The jaccard score is a measure of the overlap between the predicted and true masks. It is calculated as TP / (TP + FP + FN). If there are multiple labels, the jaccard score is the mean of the jaccard scores for each label.

Type:

float

sensitivity

Sensitivity/recall/true positive rate. The sensitivity is the proportion of true positives that are correctly identified. It is calculated as TP / (TP + FN). If there are multiple labels, the sensitivity is the mean of the sensitivities for each label.

Type:

float

specificity

Specificity/selectivity/true negative rate. The specificity is the proportion of true negatives that are correctly identified. It is calculated as TN / (TN + FP). If there are multiple labels, the specificity is the mean of the specificities for each label.

Type:

float

precision

Precision/positive predictive value. The precision is the proportion of predicted positives that are true positives. It is calculated as TP / (TP + FP). If there are multiple labels, the precision is the mean of the precisions for each label.

Type:

float

accuracy

Accuracy. The accuracy is the proportion of true results (both true positives and true negatives) among the total number of cases examined. It is calculated as (TP + TN) / (TP + TN + FP + FN). If there are multiple labels, the accuracy is the mean of the accuracies for each label.

Type:

float

mean_surface_distance

The mean surface distance, defaults to symmetric. The mean surface distance is the average distance between the surfaces of the predicted and true masks. If symmetric is True, the mean surface distance is the average of the mean surface distance from surface A to surface B and the mean surface distance from surface B to surface A. If symmetric is False, a tuple is returned with both mean surface distances. If there are multiple labels, the mean surface distance is the mean of the mean surface distances for each label.

Type:

float or tuple

hausdorff_distance

The robust Hausdorff distance, defaults to 95th percentile. The Hausdorff distance is the maximum distance of a set to the nearest point in the other set. The robust Hausdorff distance is the distance at a specified percentile of the distances from points on one surface to the other surface. If there are multiple labels, the Hausdorff distance is the mean of the Hausdorff distances for each label.

Type:

float

true_volume

The volume of the true mask (in milliliters). If there are multiple labels, the true volume is the sum of the true volumes for each label.

Type:

float

predicted_volume

The volume of the predicted mask (in milliliters) If there are multiple labels, the predicted volume is the sum of the predicted volumes for each label.

Type:

float

volume_difference

The difference between the true and predicted volumes (in milliliters). Positive values show the predicted volume is larger than the true volume, negative values show the true volume is larger than the predicted volume. If there are multiple labels, the volume difference is the sum of the absolute volume differences for each label, rather than the overall volume difference. This is to prevent positive and negative differences cancelling each other out.

Type:

float

__init__(prediction, truth, zoom, percentile=95, symmetric=True, many_labels=False)[source]

Initialises the SegmentationMetrics class instance.

Parameters:
  • prediction (np.ndarray) – An array of bools or ints representing the predicted mask.

  • truth (np.ndarray) – An array of bools or ints representing the ground truth mask.

  • zoom (tuple) – The length of each voxel dimension in millimeters.

  • percentile (int, default 95) – The percentile of surface distances to define as the Hausdorff distance.

  • symmetric (bool, default True) – If true, the symmetric mean surface distance is calculated i.e. the returned mean surface distance is the average of the means surface distance from surface A to surface B and the mean surface distance from surface B to surface A. If false, a tuple is returned with both mean surface distances.

  • many_labels (bool, default False) – If false, an error is raised if there are more than 10 labels in either the prediction or true mask. This is to prevent accidentally running the metrics on a non-binary mask (e.g. the image that was segmented). If true, metrics are calculated and averaged across all labels.

get_df()[source]

Generate a Pandas DataFrame containing the segmentation accuracy metrics.

Returns:

df – DataFrame with metric in one column and score in the next column.

Return type:

pd.DataFrame

get_dict()[source]

Generate a dictionary of segmentation accuracy metrics.

Returns:

metrics – Segmentation accuracy.

Return type:

dict

Module contents