Score Module

This module contains code for assessing the accuracy of automatic nuclei detection.

The strategy is to match automatically detected nuclei centroids with human-annotated centroids using by solving a linear-sum assignment problem to match corresponding centroids. After matching, unmatched detections and human annotations are considered false positives (FP) and false negatives (FN), respectively.

scout.score.f_score(n_true_positive, n_false_positive, n_false_negative)

Compute f-score (f-measure) from true/false positive/negative

Parameters
  • n_true_positive (int) – # of true positives in sample

  • n_false_positive (int) – # of false positives in sample

  • n_false_negative (int) – # of false negatives in sample

Returns

f-score – the harmonic mean of precision and recall

Return type

float

scout.score.main()

Compute f-score, precision and recall from the command-line

scout.score.match_centroids(c1, c2, max_distance, inf=100000.0)

Find the best matching of centroids in c1 to centroids in c2

Match centroids in c1 to those in c2, minimizing total distance between pairs with the constraint that no match is further away than max_distance.

Parameters
  • c1 (array) – an N1xM array of centroid coordinates (M is the dimension of the volume).

  • c2 (array) – another N2xM array of centroid coordinates

  • max_distance (float) – the maximum allowed distance between pairs

  • inf (float) – a ridiculously large distance to use in place of true infinity

Returns

  • c1_idxs (array) – the index of the matching centroid in c2 for each c1. Index -1 means no match.

  • c2_idxs (array) – the index of the matching centroid in c1 for each c2. Index of -1 means no match.

scout.score.parse_into_array(path)

Parse either a numpy or json-format array

Parameters

path (str) – path to array saved using either numpy.save or json.dump

scout.score.precision(n_true_positive, n_false_positive)

Compute precision from true/false positive/negative

Parameters
  • n_true_positive (int) – # of true positives in sample

  • n_false_positive (int) – # of false positives in sample

Returns

precision – true positives / (true positives + false positives)

Return type

float

References

“precision is the fraction of relevant instances among the retrieved instances 1

1

https://en.wikipedia.org/wiki/Precision_and_recall

scout.score.recall(n_true_positive, n_false_negative)

Compute recall from true/false positive/negative

Parameters
  • n_true_positive (int) – # of true positives in sample

  • n_false_negative (int) – # of false negatives in sample

Returns

recall – positives / (true positives + false negatives)

Return type

float

References

“recall is the fraction of relevant instances that have been retrieved over the total amount of relevant instances 2

2

https://en.wikipedia.org/wiki/Precision_and_recall

scout.score.score_centroids(c_detected, c_gt, max_distance)

Compute precision/recall stats on centroids

Find the best match of detected to ground-truth and then compute precision, recall and f_score from those.

Parameters
  • c_detected (array) – an N1xM array of the detected centroids

  • c_gt (array) – an N2xM array of the ground-truth centroids

  • max_distance (float) – maximum allowed distance of a match

Notes

a CentroidsScore contains the following attributes:
gt_per_detected

an array of the indices of the ground-truth match for each detected centroid. An index of -1 indicates that there was no match (false positive)

detected_per_gt

an array of the indices of the detected match for each ground-truth centroid. An index of -1 indicates that there was no match (false negative)

precision

the precision of matching - # truly detected / # detected

recall

the recall of matching # truly detected / # in ground truth

f_score

the f-score

Returns

CentroidScore – a CentroidsScore object with the final metrics

Return type

object