Skip to content

Accelerate direct and fused Sobel - #49

Merged
rsasaki0109 merged 1 commit into
mainfrom
agent/sobel-direct-output
Jul 16, 2026
Merged

Accelerate direct and fused Sobel#49
rsasaki0109 merged 1 commit into
mainfrom
agent/sobel-direct-output

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

What

  • add exact direct first-order 3x3 Sobel APIs for grayscale u8 to f32
  • add fused saturated-absolute and binary-threshold Sobel APIs with caller-owned outputs
  • borrow packed NumPy inputs without copying and explicitly pack strided inputs
  • add randomized OpenCV comparison coverage, Criterion cases, Pages documentation, and a dated receipt

Why

The canonical CPU table showed standalone Sobel trailing OpenCV by 20.31x to 23.30x at large resolutions. The generic path allocated a full-image f64 separable intermediate, while the Python binding also copied packed input.

Impact

  • exact CV_32F-compatible Sobel X is 1.88x faster at 1080p and 2.03x faster at 4K; VGA remains an OpenCV 1.07x win
  • fused abs(Sobel X) > 96 masks are 3.81x to 6.64x faster in allocate mode and 2.95x to 8.68x faster with caller-owned output
  • 300 randomized X/Y cases and all canonical outputs are bit-exact
  • no unsafe; generic Sobel remains the fallback for other kernels/orders/types

Checks

  • cargo test -p spatialrust-vision --features imgproc-filter
  • cargo clippy -p spatialrust-vision --features imgproc-filter --benches -- -D warnings
  • cargo check --manifest-path crates/spatialrust-py/Cargo.toml
  • .venv/Scripts/python.exe -m pytest crates/spatialrust-py/tests/test_bindings.py -q -k "advanced_filters or spatial_gradient or sobel"
  • .venv/Scripts/python.exe bench/opencv_sobel_threshold_comparison/performance.py --output target/opencv-sobel-threshold-performance.json
  • .venv/Scripts/python.exe bench/opencv_vision_comparison/performance.py --profiles vga,1080p,4k --output target/opencv-comparison/vision-performance-sobel-direct.json

@rsasaki0109
rsasaki0109 marked this pull request as ready for review July 16, 2026 00:49
@rsasaki0109
rsasaki0109 merged commit f5cd429 into main Jul 16, 2026
86 of 92 checks passed
@rsasaki0109
rsasaki0109 deleted the agent/sobel-direct-output branch July 16, 2026 00:53
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