Skip to content

feat(annotators): add LabelMapAnnotator - #3047

Open
Borda wants to merge 2 commits into
developfrom
feat/label-map-annotator
Open

Borda wants to merge 2 commits into
developfrom
feat/label-map-annotator

Conversation

@Borda

@Borda Borda commented Nov 22, 2026

Copy link
Copy Markdown
Member

Changes:

  • New LabelMapAnnotator in annotators/label_map.py colours an (H, W) integer class-id map over a scene through one colour lookup table built from a ColorPalette, with opacity and a background_id left unpainted
  • Class i takes palette colour i with wrap-around, negative ids are never painted, and a map that is not 2-D integer, not the scene's size, or spans more than 1,048,576 ids raises ValueError
  • Exported as sv.LabelMapAnnotator and listed in docs/detection/annotators.md
  • Tests in tests/annotators/test_label_map.py cover palette colours, background and negative ids, opacity, in-place drawing, Pillow scenes, integer widths, validation errors and parity with MaskAnnotator on Detections.from_semantic_segmentation
  • Changelog entry under Unreleased

Impact:

  • A semantic segmentation map can be drawn from one array the size of the image instead of one mask per class

Limitations:

  • Draws only on 3-channel uint8 scenes and needs a map of the scene's size
  • The changelog entry has no pull request link yet

Changes:
- New LabelMapAnnotator in annotators/label_map.py colours an (H, W) integer class-id map over a scene through one colour lookup table built from a ColorPalette, with opacity and a background_id left unpainted
- Class i takes palette colour i with wrap-around, negative ids are never painted, and a map that is not 2-D integer, not the scene's size, or spans more than 1,048,576 ids raises ValueError
- Exported as sv.LabelMapAnnotator and listed in docs/detection/annotators.md
- Tests in tests/annotators/test_label_map.py cover palette colours, background and negative ids, opacity, in-place drawing, Pillow scenes, integer widths, validation errors and parity with MaskAnnotator on Detections.from_semantic_segmentation
- Changelog entry under Unreleased

Impact:
- A semantic segmentation map can be drawn from one array the size of the image instead of one mask per class

Limitations:
- Draws only on 3-channel uint8 scenes and needs a map of the scene's size
- The changelog entry has no pull request link yet

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda
Borda requested a balanced review from Copilot November 22, 2026 23:18
@Borda
Borda requested a review from SkalskiP as a code owner November 22, 2026 23:18
@Borda Borda added the enhancement New feature or request label Nov 22, 2026
@Borda Borda changed the title feat(annotators): add LabelMapAnnotator feat(annotators): add LabelMapAnnotator Nov 22, 2026
Changes:
- The LabelMapAnnotator changelog entry ends with a link to its pull request

Impact:
- The entry meets the changelog rule that a functional change links its pull request

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Valid label maps with near-limit integer IDs can fail palette indexing or lose precision because absolute-ID range generation may produce floating-point values.

1 open issue
What changed in this PR

Adds sv.LabelMapAnnotator to render semantic segmentation class-ID maps directly, without first creating per-class detection masks.

Changes:

  • Implements palette-based coloring with opacity, background exclusion, negative-ID handling, and input validation.
  • Exports the annotator publicly and documents it in the API reference and changelog.
  • Adds tests for rendering, integer dtypes, Pillow input, in-place updates, validation, and parity with MaskAnnotator.
File Description
tests/​annotators/​test_label_map.py Tests rendering behavior, validation, and mask-rendering parity.
src/​supervision/​annotators/​label_map.py Implements class-map validation, color lookup, and blending.
src/​supervision/​__init__.py Exports LabelMapAnnotator as public API.
docs/​detection/​annotators.md Adds the annotator’s API reference.
docs/​changelog.md Announces the feature under Unreleased.

Review effort: Balanced

Comment on lines +145 to +146
ids = np.arange(lowest, highest + 1)
table = palette[ids % len(palette)]
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.31250% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 95%. Comparing base (f9f5ee6) to head (b728350).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #3047   +/-   ##
=======================================
  Coverage       95%     95%           
=======================================
  Files           84      85    +1     
  Lines        15503   15567   +64     
=======================================
+ Hits         14772   14833   +61     
- Misses         731     734    +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants