Skip to content

feat: add segmentation mask quality utilities#2263

Open
Aniketiitk21 wants to merge 2 commits into
roboflow:developfrom
Aniketiitk21:feat/segmentation-mask-quality-utilities
Open

feat: add segmentation mask quality utilities#2263
Aniketiitk21 wants to merge 2 commits into
roboflow:developfrom
Aniketiitk21:feat/segmentation-mask-quality-utilities

Conversation

@Aniketiitk21
Copy link
Copy Markdown

@Aniketiitk21 Aniketiitk21 commented May 21, 2026

Description

Adds small, composable segmentation mask quality utilities for comparing a predicted binary mask with a target mask.

Type of Change

  • New feature (non-breaking change which adds functionality)

Motivation and Context

Supervision already provides mask_iou_batch and strong segmentation support through Detections.mask and CompactMask. This PR adds single-mask quality primitives that are easy to reuse in segmentation model debugging, annotation QA, dataset inspection, and contour-sensitive evaluation workflows.

Changes Made

  • Added mask_iou, dice_coefficient, boundary_iou, and boundary_f_score
  • Added tests for overlap math, boundary tolerance behavior, empty-mask semantics, dtype handling, validation, and CompactMask parity
  • Added docs/examples and a docs navigation entry for the new utilities

Testing

  • I have tested this code locally
  • I have added unit tests that prove my feature works
  • All new tests pass locally

Commands run:

python -m venv .venv
./.venv/Scripts/python.exe -m pip install -e . pytest ruff mypy
./.venv/Scripts/python.exe -m pip install mypy==1.15.0
./.venv/Scripts/python.exe -m ruff check src/supervision/detection/utils/mask_metrics.py tests/detection/utils/test_mask_metrics.py src/supervision/__init__.py
./.venv/Scripts/python.exe -m mypy src/supervision/detection/utils/mask_metrics.py
./.venv/Scripts/python.exe -m pytest tests/detection/utils/test_mask_metrics.py -q
./.venv/Scripts/python.exe -m pytest src/supervision/detection/utils/mask_metrics.py -q

Google Colab

Colab link: N/A

Screenshots/Videos

N/A

Additional Notes

Semantics are explicit and documented:

  • both masks empty -> 1.0
  • one mask empty -> 0.0
  • tolerance is an integer pixel distance for boundary matching

This PR is intentionally focused as PR 1 of a broader segmentation quality toolkit roadmap and does not include reports, error maps, or visualization helpers yet.

@Aniketiitk21 Aniketiitk21 requested a review from SkalskiP as a code owner May 21, 2026 02:34
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 21, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants