Skip to content

fix(annotators): preserve grayscale channel axis in blur and pixelation - #2725

Merged
Borda merged 7 commits into
roboflow:developfrom
Nikhi00718:fix/annotators-single-channel-grayscale
Oct 15, 2026
Merged

Borda merged 7 commits into
roboflow:developfrom
Nikhi00718:fix/annotators-single-channel-grayscale

Conversation

@Nikhi00718

Copy link
Copy Markdown
Contributor

Description

BlurAnnotator and PixelateAnnotator raise ValueError on grayscale frames shaped (H, W, 1) when native OpenCV is installed:

import numpy as np
import supervision as sv

image = np.arange(30 * 40, dtype=np.uint8).reshape(30, 40, 1)
detections = sv.Detections(xyxy=np.array([[2, 3, 22, 19]], dtype=np.float32))
sv.BlurAnnotator(kernel_size=3).annotate(image.copy(), detections)
sv.PixelateAnnotator(pixel_size=4).annotate(image.copy(), detections)

Both calls fail with could not broadcast input array from shape (16,20) into shape (16,20,1).

Motivation and Context

OpenCV's blur and resize remove the singleton channel axis. Assigning their two-dimensional result into a three-dimensional region then fails. The NumPy fallback retains that axis, so the same pipeline works without OpenCV and fails when it is installed.

Changes Made

Restore each filtered region to its original shape before writing it back to the scene. Document both grayscale layouts and add regressions comparing (H, W, 1) output with (H, W) output for rectangular, small, single-row and single-column regions, including in-place behavior.

Testing

  • New regression cases on unmodified develop: 5 failed, 3 passed with OpenCV 5.0.0.

  • Fixed regressions and adjacent blur/pixelation tests with OpenCV 5.0.0: 23 passed.

  • Complete annotator tests with OpenCV 4.12.0: 211 passed.

  • uv run pytest --cov=supervision with the NumPy fallback: 5,433 passed, 79 skipped, 93% coverage.

  • uv run pre-commit run --all-files: all hooks passed.

  • Added/updated tests, and the full suite passes locally

  • Updated docs (docstrings / mkdocs entry) for new or changed public API

  • Added changelog under Unreleased

Additional Notes

No new dependencies or API parameters.

@Nikhi00718
Nikhi00718 requested a review from SkalskiP as a code owner October 13, 2026 10:48
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (8185496) to head (a59c9cc).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2725   +/-   ##
=======================================
- Coverage       94%     94%   -0%     
=======================================
  Files           83      83           
  Lines        13127   13127           
=======================================
- Hits         12323   12320    -3     
- Misses         804     807    +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the bug Something isn't working label Oct 13, 2026
@Borda
Borda requested a balanced review from Copilot October 13, 2026 12:18

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.

🟢 Approval recommended

The implementation is correct and well tested; remaining feedback is non-blocking metadata and test-ID cleanup.

2 open findings
What changed in this PR

Fixes grayscale (H, W, 1) handling in privacy annotators while preserving in-place behavior.

Changes:

  • Restores singleton channel axes after OpenCV blur/resize operations.
  • Adds regression coverage and API documentation.
  • Adds an Unreleased changelog entry.

Review scores: Code quality 5/5 · Testing 4/5 · Documentation 4/5

File Description
src/​supervision/​annotators/​core.py Preserves grayscale ROI shape after filtering.
tests/​annotators/​test_core.py Tests grayscale layouts and edge-case regions.
docs/​changelog.md Documents the bug fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/changelog.md Resolved
Comment thread tests/annotators/test_core.py Resolved
…gle-channel-grayscale

# Conflicts:
#	docs/changelog.md
Borda and others added 2 commits October 15, 2026 14:13
Changes:
- Integrate develop video-reader cancellation, cleanup error handling, and regression tests.
- Integrate coincident-label separation and its regression tests.
- Retain updated model and annotation examples, typing adjustments, and notebook dependency lock updates.
- Reconcile changelog additions, preserving the grayscale fix entry and the newer modification date.

Impact:
- Preserve the PR's grayscale channel handling atop the current target implementation.
- Remove the changelog merge conflict while retaining target behavior and release notes.

Verification:
- Annotator tests: 211 passed.
- Full suite in the existing project environment: 5589 passed, 79 skipped, 94% coverage.
- All configured pre-commit hooks passed; staged diff whitespace check passed.

Residual limits:
- Native OpenCV reproduction and independent reviewer coverage remain open review obligations.
- Automatic environment synchronization requires uncached notebook dependencies; checks used the existing environment without synchronization.

---

Co-authored-by: Codex <[email protected]>
@Borda
Borda merged commit 02ce5f8 into roboflow:develop Oct 15, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants