Skip to content

fix(filtering): validate kernel size and anchor in Box Filter, Erosion and Dilation - #419

Merged
ivantha merged 1 commit into
c2siorg:mainfrom
rishiraj38:fix/filter-kernel-anchor-validation
Oct 19, 2026
Merged

ivantha merged 1 commit into
c2siorg:mainfrom
rishiraj38:fix/filter-kernel-anchor-validation

Conversation

@rishiraj38

Copy link
Copy Markdown
Contributor

Description

Box Filter passed width / height, and Box Filter, Erosion and Dilation passed point_x / point_y, straight to cv2.boxFilter, cv2.erode and cv2.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:

  • Add validate_anchor_point to app/operators/filtering/validation.py, same rule and message as the Blur one: -1 (centre) or 0 <= value < kernel size, otherwise a ValueError such as "'point_x' must be -1 (centre) or between 0 and 4 for a kernel size of 5, got 9."
  • box_filter.py: check width and height with the existing validate_positive_kernel_dim, then point_x against width and point_y against height.
  • erosion.py / dilation.py: check point_x and point_y against the kernel size actually used, after the existing odd/minimum adjustment.
  • filtering.blocks.ts: Box Filter width and height now have min: 1 (was 0), and the pointX / pointY fields on all three blocks have min: -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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

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 on main and pass with this change.

  • New tests/operators/filtering/test_validation.py for validate_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 . and uv run ruff format --check . pass.

  • uv run pytest: all tests pass except tests/test_histogram_stats.py::test_calculate_channel_statistics_rgb, which also fails on main on macOS and is unrelated.

  • Frontend: npm run lint, Prettier check, tsc -b and npm run test pass.

  • Existing tests pass

  • New tests added

  • Manual testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review
  • I have added/updated documentation as needed
  • My changes generate no new warnings
  • Tests pass locally

…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.
@ivantha ivantha added bug Something isn't working ready-for-maintainer Reviewed; looks mergeable, awaiting maintainer labels Oct 19, 2026
@ivantha

ivantha commented Oct 19, 2026

Copy link
Copy Markdown
Member

Automated review summary

Triage: bug | Recommendation: ready-for-maintainer

Findings

  • None flagged.

Conventions

  • PR title: follows Conventional Commits
  • Description: clear and complete
  • Commits (1): clean, conventional history

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 /review-prs. A maintainer will follow up.

@ivantha
ivantha merged commit 437f695 into c2siorg:main Oct 19, 2026
5 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 ready-for-maintainer Reviewed; looks mergeable, awaiting maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Box Filter, Erosion and Dilation show raw OpenCV assertion errors for a zero-size kernel or an anchor outside the kernel

2 participants