Skip to content

perf(vision): accelerate connected components beyond OpenCV - #38

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

rsasaki0109 merged 1 commit into
mainfrom
agent/connected-components-opencv-performance

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

What changed

  • replace queue-based per-pixel connected-component flood fill with row-run scanning and path-compressed union-find
  • preserve consecutive row-major labels for both 4- and 8-connectivity while accumulating areas, boxes, and pixel-center centroids analytically
  • add a borrowed packed-u8 Rust API and make Python borrow contiguous masks, accept any non-zero foreground byte, and move label storage into NumPy
  • add independent flood-fill regressions, non-contiguous Python coverage, Criterion profiles, an OpenCV SAUF harness, GitHub Pages updates, and a dated receipt

Why

The prior flood fill repeatedly queued pixels and generated full neighborhoods inside each component. Structured segmentation and document masks contain long horizontal runs, so labeling runs and joining only overlaps in the previous row removes most queue and neighbor traffic.

Measured impact

On the documented Windows 11 / Intel 6-core host, SpatialRust is 2.17x to 3.61x faster than OpenCV 4.13 CCL_SAUF across structured VGA, 1080p, and 4K segmentation-blob and document-line masks. Labels, areas, and bounding boxes match exactly on all six profiles and 320 additional seeded randomized 4/8-connectivity cases.

The claim is deliberately scoped to structured masks; highly fragmented or dense random noise still favors OpenCV.

Validation

  • cargo test -p spatialrust-vision --features dense (19 passed)
  • cargo clippy -p spatialrust-vision --all-targets --features dense -- -D warnings
  • cargo clippy --manifest-path crates/spatialrust-py/Cargo.toml --all-targets -- -D warnings
  • Python binding tests (67 passed, 1 skipped)
  • OpenCV report contract tests (8 passed)
  • OpenCV harness schema validation and 320 randomized SAUF cases
  • changed Rust files pass rustfmt --check
  • cargo doc -p spatialrust-vision --features dense --no-deps
  • Criterion VGA/1080p/4K structured-mask profiles

Workspace-wide rustfmt still reports the repository's pre-existing formatting baseline in unrelated files; this slice does not modify those files.

@rsasaki0109
rsasaki0109 marked this pull request as ready for review July 15, 2026 14:44
@rsasaki0109
rsasaki0109 merged commit 52efb2c into main Jul 15, 2026
86 of 92 checks passed
@rsasaki0109
rsasaki0109 deleted the agent/connected-components-opencv-performance branch July 15, 2026 14:48
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