Repository navigation
Conversation
`MaskAnnotator` and `HaloAnnotator` raised `ValueError` on grayscale scenes, shaped `(H, W)` or `(H, W, 1)` or given as a Pillow "L" image, because `_paint_masks_by_area` assigned a three-value BGR color to single-channel pixels. Other annotators draw on the same scenes through OpenCV, which writes the first (blue) channel of the color. Paint grayscale canvases with that first channel, restore the singleton channel axis that OpenCV drops in `addWeighted` and `blur`, and compute the halo alpha from the single channel instead of `COLOR_BGR2GRAY`. BGR scenes are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2755 +/- ##
=======================================
Coverage 94% 94%
=======================================
Files 83 83
Lines 13638 13644 +6
=======================================
+ Hits 12833 12839 +6
Misses 805 805 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The localized channel-handling changes preserve BGR behavior and include focused grayscale regression coverage.
No open issues 🎉
What changed in this PR
🟢 Approve — extends Supervision’s grayscale annotation support to masks and halos. No actionable issues were identified.
Changes:
- Paint grayscale masks using the color’s blue channel, matching existing OpenCV drawing behavior.
- Preserve singleton channel dimensions during blending and halo generation.
- Add regression tests, docstrings, and a changelog entry.
Coverage: behavior, shape compatibility, tests, and documentation. Tests were not independently run.
Quality: code 5/5, testing 4/5, documentation 5/5; risk 1/5. Changes are localized and have focused regression coverage.
| File | Description |
|---|---|
| tests/annotators/test_core.py | Adds grayscale layout, compact-mask, color-value, and Pillow regressions. |
| src/supervision/annotators/core.py | Handles single-channel mask painting, blending, and halos. |
| docs/changelog.md | Documents grayscale support and color behavior. |
Review effort: Balanced
Changes: - Merge target roboflow#2750 and roboflow#2752 metrics behavior and regression coverage into the PR branch. - Retain the PR roboflow#2755 grayscale annotator changelog entry alongside target metrics release notes. Impact: - Keeps the PR branch current with develop while preserving both PR and target behavior. - Retains release notes for grayscale annotator and metrics changes in one Unreleased section. Verification: - `git merge-tree` identified one changelog conflict; the resolution keeps all three independent entries. - Reviewed the five-path merge index; no unmerged paths remain and `git diff --cached --check` passes. Residual limits: - The conflict was documentation-only; merged target code remains subject to this remediation run's quality gates. --- Co-authored-by: Codex <[email protected]>
Changes: - Add a HaloAnnotator grayscale regression with non-neutral colors that differ only in the blue component. Impact: - Protects the documented first BGR component behavior from future grayscale channel-selection regressions. Verification: - Canonical gates passed: ruff lint and format, mypy, and coverage tests (5,763 passed, 123 skipped, 39 warnings). - The wrong red-channel mutation failed the new assertion; exact source restoration was verified and the focused test passed. - git diff --check passed. Residual limits: - The admitted review's specialist assessments were parent substitutes; independent multi-role coverage remains unavailable. - Tests used the pure NumPy fallback because OpenCV is not installed. --- Co-authored-by: Codex <[email protected]>
Borda
approved these changes
Oct 19, 2026
Borda
added a commit
that referenced
this pull request
Oct 20, 2026
`MaskAnnotator` and `HaloAnnotator` raised `ValueError` on grayscale scenes, shaped `(H, W)` or `(H, W, 1)` or given as a Pillow "L" image, because `_paint_masks_by_area` assigned a three-value BGR color to single-channel pixels. Other annotators draw on the same scenes through OpenCV, which writes the first (blue) channel of the color. Paint grayscale canvases with that first channel, restore the singleton channel axis that OpenCV drops in `addWeighted` and `blur`, and compute the halo alpha from the single channel instead of `COLOR_BGR2GRAY`. BGR scenes are unchanged. --------- Co-authored-by: jirka <[email protected]> Co-authored-by: Codex <[email protected]>
2 of 3 tasks
3 tasks done
2 of 3 tasks
This was referenced Nov 3, 2026
This was referenced Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MaskAnnotatorandHaloAnnotatorraiseValueErroron grayscale scenes:(H, W)arrays,(H, W, 1)arrays, and Pillow"L"images (whichpillow_to_cv2turns into(H, W)arrays).BoxAnnotator,PolygonAnnotatorandColorAnnotatoralready work on the same scenes.Before (develop):
After (color
sv.Color(r=10, g=20, b=200)):Motivation and Context
_paint_masks_by_areawritescolor.as_bgr(), a three-value color, into every canvas pixel under a mask. A single-channel canvas cannot take three values. The other annotators draw through OpenCV (cv2.rectangle,cv2.fillPoly), and OpenCV writes the color's first (blue) value on a one-channel image. Grayscale scenes are already supported elsewhere:pillow_to_cv2returns(H, W)arrays for single-channel Pillow modes, and #2725 fixed the same layouts inBlurAnnotatorandPixelateAnnotator.Changes Made
_paint_masks_by_areanow paints a grayscale canvas with the first channel of the color, so a mask gets the same gray value as the box or polygon outline for that detection.MaskAnnotator: restore the singleton channel axis that OpenCV'saddWeighteddrops before writing the blend back.HaloAnnotator: restore the channel axis afterblur, clear the mask area with a scalar, and take the halo alpha straight from the single channel instead ofCOLOR_BGR2GRAY.annotatemethods describe the grayscale layouts.Testing
New
TestSingleChannelMaskAnnotators(12 cases): mask and halo on(H, W)and(H, W, 1)scenes, with dense masks andCompactMask, must equal channel 0 of the same annotation on the BGR copy of the scene. A gray mask must takecolor.b, likePolygonAnnotatorandColorAnnotator. A Pillow"L"image must come back as an"L"image.On
develop: 6 failed, 2 passed (the polygon and color reference cases). With this change: 12 passed, with OpenCV 5.0 and with the NumPy fallback.pytestfull suite with OpenCV: 6069 passed, 1 skipped. Without OpenCV: 5741 passed, 123 skipped.pre-commit runon the changed files: ruff, ruff-format, docformatter, codespell and the other hooks pass. mypy reports no new errors.Added/updated tests, and the full suite passes locally
Updated docs (docstrings / mkdocs entry) for new or changed public API
Added a changelog entry in
docs/changelog.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
On a grayscale scene a color has no single obvious gray. I used the first (blue) channel because that is what every OpenCV-drawn annotator already writes, so masks, boxes and polygons on the same frame agree. Converting colors to luminance would need the same change in all of those annotators, which is beyond this fix.
CropAnnotator,BackgroundOverlayAnnotator,HeatMapAnnotatorandRichLabelAnnotatoralso fail on grayscale scenes; I left them for separate PRs.