perf(vision): accelerate connected components beyond OpenCV - #38
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
u8Rust API and make Python borrow contiguous masks, accept any non-zero foreground byte, and move label storage into NumPyWhy
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 warningscargo clippy --manifest-path crates/spatialrust-py/Cargo.toml --all-targets -- -D warningsrustfmt --checkcargo doc -p spatialrust-vision --features dense --no-depsWorkspace-wide rustfmt still reports the repository's pre-existing formatting baseline in unrelated files; this slice does not modify those files.