Skip to content

make pixel and kernel size dynamic#709

Merged
Borda merged 7 commits into
roboflow:developfrom
Clemens-E:improve-pixelate-and-blur
Mar 30, 2026
Merged

make pixel and kernel size dynamic#709
Borda merged 7 commits into
roboflow:developfrom
Clemens-E:improve-pixelate-and-blur

Conversation

@Clemens-E

@Clemens-E Clemens-E commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

Description

Fixes #703

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [?] This change requires a documentation update

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

  • Docs updated? What were the changes:

@CLAassistant

CLAassistant commented Jan 3, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Clemens-E

Copy link
Copy Markdown
Contributor Author

Sorry I'm a bit lost with the tests cases, what would I have to adjust?

Borda and others added 2 commits March 30, 2026 20:50
- 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

codecov Bot commented Mar 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77%. Comparing base (9ed1f07) to head (3e60dd7).
⚠️ Report is 1 commits behind head on develop.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

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 BlurAnnotator and PixelateAnnotator to 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.

Comment thread src/supervision/annotators/core.py
Comment thread src/supervision/annotators/core.py
Comment thread src/supervision/annotators/core.py Outdated
Comment thread src/supervision/annotators/core.py
Borda and others added 3 commits March 30, 2026 21:55
- 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 Borda mentioned this pull request Apr 17, 2026
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.

PixelateAnnotator throws errors if the area is too small, BlurAnnotator is not censoring if area is too large

4 participants