segmentationmetrics package
Subpackages
- segmentationmetrics.surface_distance package
- segmentationmetrics.tests package
- Submodules
- segmentationmetrics.tests.test_metrics module
TestSegmentationMetricsTestSegmentationMetrics.ball_aTestSegmentationMetrics.ball_bTestSegmentationMetrics.ball_cTestSegmentationMetrics.ball_dTestSegmentationMetrics.ball_eTestSegmentationMetrics.ball_fTestSegmentationMetrics.canvasTestSegmentationMetrics.centre_aTestSegmentationMetrics.centre_bTestSegmentationMetrics.centre_cTestSegmentationMetrics.centre_dTestSegmentationMetrics.centre_eTestSegmentationMetrics.centre_fTestSegmentationMetrics.img_aTestSegmentationMetrics.img_bTestSegmentationMetrics.img_cTestSegmentationMetrics.img_dTestSegmentationMetrics.img_eTestSegmentationMetrics.img_fTestSegmentationMetrics.img_shapeTestSegmentationMetrics.radius_aTestSegmentationMetrics.radius_bTestSegmentationMetrics.radius_cTestSegmentationMetrics.radius_dTestSegmentationMetrics.radius_eTestSegmentationMetrics.radius_fTestSegmentationMetrics.test_2d()TestSegmentationMetrics.test_all_wrong()TestSegmentationMetrics.test_basic_case()TestSegmentationMetrics.test_float_case()TestSegmentationMetrics.test_many_labels_error()TestSegmentationMetrics.test_multilabel_basic()TestSegmentationMetrics.test_multilabel_labels_dont_overlap()TestSegmentationMetrics.test_multilabel_missing_label()TestSegmentationMetrics.test_multilabel_with_options()TestSegmentationMetrics.test_multilabel_with_options_missing_label()TestSegmentationMetrics.test_no_labels()TestSegmentationMetrics.test_no_overlap()TestSegmentationMetrics.test_non_consecutive_labels()TestSegmentationMetrics.test_nonisotropic_voxels()TestSegmentationMetrics.test_options()
assert_dict_approx()
- segmentationmetrics.tests.test_surface_distance module
SurfaceDistance2DTestSurfaceDistance3DTestSurfaceDistanceTestSurfaceDistanceTest.test_compute_surface_distances_raises_on_incompatible_shapes0()SurfaceDistanceTest.test_compute_surface_distances_raises_on_incompatible_shapes1()SurfaceDistanceTest.test_compute_surface_distances_raises_on_incompatible_shapes2()SurfaceDistanceTest.test_compute_surface_distances_raises_on_invalid_shapes0()SurfaceDistanceTest.test_compute_surface_distances_raises_on_invalid_shapes1()
- Module contents
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.