Repository navigation
fix(filtering): validate kernel size and anchor in Box Filter, Erosion and Dilation - #419
Merged
ivantha merged 1 commit intoOct 19, 2026
Conversation
…n and Dilation Box Filter passed width and height, and Box Filter, Erosion and Dilation passed point_x and point_y, straight to OpenCV. A zero-size kernel or an anchor outside the kernel failed with a raw OpenCV assertion message. Validate them before the OpenCV call, the same way c2siorg#396 did for Apply Blur, and set matching minimums on the block fields.
Member
Automated review summaryTriage: bug | Recommendation: ready-for-maintainer Findings
Conventions
The PR adds a shared validate_anchor_point helper and applies it to Box Filter (width/height and anchors), Erosion and Dilation. A bad kernel size or anchor now raises a clear ValueError instead of a raw OpenCV assertion. The anchor logic is correct: x is checked against width and y against height for Box Filter, and Erosion/Dilation check against the kernel size after the odd/minimum adjustment. Frontend min constraints match the backend rules, and the new tests cover the invalid, valid and edge cases. Nothing blocking. I did not run CI or the tests myself, so confirm lint and tests pass before a rebase-and-merge. Generated by |
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
Box Filter passed
width/height, and Box Filter, Erosion and Dilation passedpoint_x/point_y, straight tocv2.boxFilter,cv2.erodeandcv2.dilate. A zero-size kernel or an anchor outside the kernel failed with a raw OpenCV assertion, for example(-215:Assertion failed) anchor.inside(Rect(0, 0, ksize.width, ksize.height)). This follows #396 / #397, which fixed the same problem for Apply Blur.Changes:
validate_anchor_pointtoapp/operators/filtering/validation.py, same rule and message as the Blur one:-1(centre) or0 <= value < kernel size, otherwise aValueErrorsuch as "'point_x' must be -1 (centre) or between 0 and 4 for a kernel size of 5, got 9."box_filter.py: checkwidthandheightwith the existingvalidate_positive_kernel_dim, thenpoint_xagainstwidthandpoint_yagainstheight.erosion.py/dilation.py: checkpoint_xandpoint_yagainst the kernel size actually used, after the existing odd/minimum adjustment.filtering.blocks.ts: Box Filter width and height now havemin: 1(was 0), and the pointX / pointY fields on all three blocks havemin: -1. There is no static max, because the valid anchor range depends on the kernel size; the backend check handles that.Fixes #418
Type of Change
How Has This Been Tested?
New tests in
tests/test_filtering_operators.py: Box Filter with width/height 0 or negative, anchors out of range in x and y, negative anchors other than -1, and valid anchors (-1/-1, 0/0, last index); the same anchor cases for Erosion and Dilation. These fail onmainand pass with this change.New
tests/operators/filtering/test_validation.pyforvalidate_anchor_point, mirroring the Blur validator tests.Ran the pipeline executor directly with the bad parameters: each step now fails with the validation message instead of the OpenCV assertion.
uv run ruff check .anduv run ruff format --check .pass.uv run pytest: all tests pass excepttests/test_histogram_stats.py::test_calculate_channel_statistics_rgb, which also fails onmainon macOS and is unrelated.Frontend:
npm run lint, Prettier check,tsc -bandnpm run testpass.Existing tests pass
New tests added
Manual testing
Screenshots (if applicable)
N/A
Checklist