Metrics
Functions:
|
Computes the dice coefficient/F1 score, a measure of average similarity. |
|
Computes the h-index given a mixture of ditributions. |
|
Computes the single weighted h-index given a mixture of ditributions. |
|
Calculates the Hausdorff distance for a given image, provided a ground truth. |
|
Calculates the IoU/jaccard index for a pair of masks. |
|
Computes the content of mask_a captured in mask_b and returns it as a percent. |
|
Computes the percent of misclassified pixels on an image. |
- cell_analysis_tools.metrics.dice(im1, im2, empty_score=1.0)[source]
Computes the dice coefficient/F1 score, a measure of average similarity.
- Parameters:
im1 (array-like, bool) – Any array of arbitrary size. If not boolean, will be converted.
im2 (array-like, bool) – Any other array of identical size. If not boolean, will be converted.
empty-score (int) – Any other array of identical size. If not boolean, will be converted.
- Returns:
Dice coefficient as a float on range [0,1].
Maximum similarity = 1
No similarity = 0
Both are empty (sum eq to zero) = empty_score
- Return type:
float
Note
The order of inputs for dice is irrelevant. The result will be identical if im1 and im2 are switched.
- cell_analysis_tools.metrics.h_index(list_distributions) float[source]
Computes the h-index given a mixture of ditributions.
- Parameters:
list_distributions (list) – List of np.arrays containing estimated subdistributions
- Returns:
calculated H-index
- Return type:
float
Notes
When comparing H-index between datasets be sure to set the n_components paramter of the GaussianMixtureModel to the same value.
References
http://www.microscopist.co.uk/wp-content/uploads/2021/06/FLIM-review.pdf
- cell_analysis_tools.metrics.h_index_single_weighted(list_distributions) float[source]
Computes the single weighted h-index given a mixture of ditributions.
- Parameters:
list_distributions (list) – List of np.arrays containing estimated subdistributions
- Returns:
calculated H-index
- Return type:
float
Notes
When comparing H-index between datasets be sure to set the n_components paramter of the GaussianMixtureModel to the same value.
- cell_analysis_tools.metrics.hausdorff_distance(mask_pred, mask_gt)[source]
Calculates the Hausdorff distance for a given image, provided a ground truth. Both arrays must have the same number of columns. see https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.directed_hausdorff.html :param mask_pred: predicted segmentation mask :type mask_pred: np.ndarray :param mask_gt: ground truth mask :type mask_gt: np.ndarray
- Returns:
ddouble – The directed Hausdorff distance between arrays u and v,
index_1int – index of point contributing to Hausdorff pair in u
index_2int – index of point contributing to Hausdorff pair in v
- cell_analysis_tools.metrics.jaccard(mask_gt, mask_pred)[source]
Calculates the IoU/jaccard index for a pair of masks.
Logic is implemented to require images of the same size.
- Parameters:
mask_pred (np.ndarray) – Ground truth numpy ndarray image.
mask_gt (np.ndarray) – Current image numpy ndarray.
- Returns:
jaccard_index – Calculated Jaccard index/distance.
- Return type:
float
- cell_analysis_tools.metrics.percent_content_captured(mask_a, mask_b)[source]
Computes the content of mask_a captured in mask_b and returns it as a percent. (A intersect B)/A # From the paper Mitohacker <https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7642274/>
- Parameters:
mask_a (ndarray) – boolean mask.
mask_b (ndarray) – boolean mask.
- Returns:
percent – percent of mask_a content captured by mask_b.
- Return type:
float
- cell_analysis_tools.metrics.total_error(mask_gt, mask_pred, weight_fn=1, weight_fp=1)[source]
Computes the percent of misclassified pixels on an image. In the case where one is more important than the other, a weighted average may be used: c0FP + c1FN
‘https://stats.stackexchange.com/questions/273537/f1-dice-score-vs-iou <https://stats.stackexchange.com/questions/273537/f1-dice-score-vs-iou>’_
- Parameters:
mask_gt (bool ndarray) – groudn truth mask.
mask_predicted (bool ndarray) – DESCRIPTION.
weight_fn (int, optional) – scalar weight applied to false negatives. The default is 1.
weight_fp (int, optional) – scalar weight applied to false positives. The default is 1.
- Returns:
percent – total error of the predicted mask given a ground truth mask.
- Return type:
float