make pixel and kernel size dynamic#709
Merged
Merged
Conversation
Contributor
Author
|
Sorry I'm a bit lost with the tests cases, what would I have to adjust? |
- Skip loop iteration when clip_boxes produces x2<=x1 or y2<=y1 (zero-area ROI) to prevent cv2.error crash in both annotators - Replace falsy `or` pattern with explicit `is not None` so kernel_size=0 / pixel_size=0 are not silently treated as dynamic --- Co-authored-by: Claude Code <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #709 +/- ##
======================================
Coverage 77% 77%
======================================
Files 62 62
Lines 7595 7615 +20
======================================
+ Hits 5861 5881 +20
Misses 1734 1734 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds dynamic sizing behavior to blur/pixelation annotators to address failures on very small regions (and improve censorship strength scaling), aligning annotator behavior with bounding-box size.
Changes:
- Add helper functions to compute dynamic blur kernel size and pixelation size from bbox dimensions.
- Update
BlurAnnotatorandPixelateAnnotatorto support dynamic sizing when the parameter is unset (None) and skip invalid/empty ROIs. - Add a Pixelate small-ROI fallback path to avoid OpenCV resize crashes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/supervision/annotators/utils.py |
Introduces bbox-based helper functions for dynamic kernel/pixel sizing. |
src/supervision/annotators/core.py |
Switches Blur/Pixelate annotators to optional dynamic sizing and adds small-ROI handling. |
- Replace hardcoded `cv2.mean(roi)[:3]` with ndim-aware fill: scalar for grayscale, channel-matched tuple for colour images; avoids shape mismatch broadcast error on single-channel frames [resolve roboflow#1] Review comment by @Copilot (PR roboflow#709): "If scene/roi is a single-channel (grayscale) array, this will fail due to shape mismatch..." --- Co-authored-by: Claude Code <noreply@anthropic.com>
- test_annotate_bbox_smaller_than_pixel_size_does_not_raise: guards against the OpenCV resize crash from issue roboflow#703 when bbox < pixel_size - test_annotate_grayscale_image_does_not_raise: normal pixelation path on 2-D grayscale frame - test_annotate_grayscale_image_small_roi_does_not_raise: avg-fill fallback on 2-D grayscale frame [resolve roboflow#2] Review comment by @Copilot (PR roboflow#709): "Please add unit tests covering: (1) PixelateAnnotator(pixel_size=...) with a bbox smaller than pixel_size..." --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Add ValueError guard in BlurAnnotator.__init__ and PixelateAnnotator.__init__ for explicit sizes < 1; previously passed straight to cv2 causing ZeroDivisionError or OpenCV assertion failures - Add parametrized tests for invalid sizes (0, -1, -10) and zero-area bbox skipping for both annotators --- Co-authored-by: Claude Code <noreply@anthropic.com>
Borda
approved these changes
Mar 30, 2026
Merged
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
Fixes #703
Type of change
Please delete options that are not relevant.
not sure on the documentation
How has this change been tested, please provide a testcase or example of how you tested the change?
I have not changed any tests
Any specific deployment considerations
For example, documentation changes, usability, usage/costs, secrets, etc.
Docs