lazyslide.metrics.segmentation.mean_iou

Contents

lazyslide.metrics.segmentation.mean_iou#

mean_iou(stats)#

Compute mean Intersection over Union (mIoU) from segmentation statistics.

This function handles both instance segmentation and semantic segmentation scenarios: - For instance segmentation: computes the mean of IoU values for matched instances - For semantic segmentation: computes IoU using the Jaccard index formula

Parameters:
statsSegmentationStats

Segmentation statistics. If stats.ious is not None (instance segmentation), uses the list of IoU values. Otherwise (semantic segmentation), uses tp, fp, and fn counts to compute IoU.

Returns:
float

Mean IoU score in the range [0, 1], where 1 indicates perfect overlap. For instance segmentation: returns 0.0 if no matches exist. For semantic segmentation: a small epsilon (1e-8) prevents division by zero.

Notes

Instance segmentation: mIoU = mean(IoU_values) Semantic segmentation: IoU = TP / (TP + FP + FN)