Skip to content

perf(vision): fuse paired Sobel gradients - #41

Merged
rsasaki0109 merged 1 commit into
mainfrom
agent/paired-sobel-fast-path
Jul 15, 2026
Merged

rsasaki0109 merged 1 commit into
mainfrom
agent/paired-sobel-fast-path

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

Summary

  • add exact OpenCV-compatible paired 3x3 Sobel APIs with caller-owned output reuse
  • add a fused abs(Gx) + abs(Gy) path that avoids materializing two gradient images
  • route the Canny 3x3 aperture through the paired gradient implementation
  • expose paired and fused operations in Python with shape, contiguity, aliasing, and reuse validation
  • add Criterion and OpenCV comparison harnesses plus GitHub Pages algorithm documentation

Why

The previous generic Sobel path traversed the source independently for X and Y and allocated intermediate images. This slice establishes a specialized paired contract and a canonical fused workload where SpatialRust can outperform OpenCV without relaxing result accuracy.

Measured impact

Windows 11, Intel 6C/12T, OpenCV 4.13.0, OpenCL disabled, 300 randomized exactness cases:

Resolution OpenCV allocated pipeline SpatialRust fused Result
1080p 5.508 ms 2.954 ms SpatialRust 1.86×
4K 22.502 ms 10.262 ms SpatialRust 2.19×
8K 97.258 ms 40.238 ms SpatialRust 2.42×

The claim is intentionally scoped to allocated L1 magnitude. Caller-owned reuse is approximately tied at 1080p and OpenCV remains slightly faster at 4K/8K. Standalone paired gradients also remain an optimization target.

Validation

  • cargo test -p spatialrust-vision --features full — 113 unit + 11 property tests passed
  • cargo clippy -p spatialrust-vision --features imgproc-canny -- -D warnings
  • cargo test -p spatialrust-vision --features imgproc-canny --lib
  • cargo test -p spatialrust-vision --features imgproc-filter advanced_filter --lib
  • cargo bench -p spatialrust-vision --features imgproc-filter --bench filter --no-run
  • cargo doc -p spatialrust-vision --features imgproc-canny --no-deps
  • Python binding suite passed (one existing skip)
  • OpenCV conformance: zero mismatch for Sobel and Canny apertures 3/5/7, L1/L2
  • focused OpenCV harness: 300 randomized exact cases passed

Rust 1.82 dependency resolution is currently blocked before compilation by the repository's floating clap_builder 4.6.0 requiring Edition 2024; this is independent of the Sobel implementation.

@rsasaki0109
rsasaki0109 marked this pull request as ready for review July 15, 2026 16:26
@rsasaki0109
rsasaki0109 merged commit 6477339 into main Jul 15, 2026
86 of 92 checks passed
@rsasaki0109
rsasaki0109 deleted the agent/paired-sobel-fast-path branch July 15, 2026 18:12
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