Skip to content

perf(vision): accelerate rectangular morphology - #39

Merged
rsasaki0109 merged 1 commit into
mainfrom
agent/rect-morphology-opencv-performance
Jul 15, 2026
Merged

rsasaki0109 merged 1 commit into
mainfrom
agent/rect-morphology-opencv-performance

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

What changed

  • add a safe separable prefix/suffix min/max engine for packed grayscale u8 rectangular morphology
  • preserve the generic fallback for other shapes, types, channels, strides, anchors, and borders
  • dispatch contiguous NumPy rectangles through the fast path and preserve non-contiguous input behavior
  • add Rust/Python parity tests, Criterion profiles, and a focused interleaved OpenCV harness
  • update the README comparison table, Epic 117 roadmap state, dated receipt, and GitHub Pages algorithm guide

Why

The previous implementation scanned every active kernel sample for every output pixel, leaving 5×5 opening hundreds of times slower than OpenCV. Rectangles are separable, so the new path computes each line with block prefix/suffix extrema and bounded parallel row/column stages.

Measured impact

  • 4K 5×5 opening: 4599.72 ms → 105.05 ms (43.8× faster than the prior SpatialRust path)
  • 1080p 511×511 opening: SpatialRust 22.559 ms vs OpenCV 55.543 ms (2.46×)
  • 4K 511×511 opening: SpatialRust 100.889 ms vs OpenCV 207.788 ms (2.06×)
  • small-window scope is reported honestly: OpenCV remains faster at 5×5

All published cases are bit-exact. The harness also passes 980 seeded randomized OpenCV comparisons across all seven operations.

Validation

  • cargo test -p spatialrust-vision --features imgproc-morphology
  • cargo clippy -p spatialrust-vision --features imgproc-morphology -- -D warnings
  • cargo bench -p spatialrust-vision --bench morphology --features imgproc-morphology --no-run
  • python -m pytest crates/spatialrust-py/tests/test_bindings.py -q (68 passed, 1 skipped)
  • python bench/opencv_morphology_comparison/performance.py --output target/opencv-morphology-performance.json

@rsasaki0109
rsasaki0109 marked this pull request as ready for review July 15, 2026 15:15
@rsasaki0109
rsasaki0109 merged commit 86a577a into main Jul 15, 2026
86 of 92 checks passed
@rsasaki0109
rsasaki0109 deleted the agent/rect-morphology-opencv-performance branch July 15, 2026 15:19
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.

1 participant