Skip to content

Add exact Euclidean distance transform - #32

Merged
rsasaki0109 merged 1 commit into
mainfrom
agent/exact-euclidean-distance-transform
Jul 15, 2026
Merged

rsasaki0109 merged 1 commit into
mainfrom
agent/exact-euclidean-distance-transform

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

What changed

  • add safe exact Euclidean distance transforms with unit and anisotropic pixel spacing
  • expose distance_transform_edt to NumPy, accepting conventional zero/nonzero masks
  • add known-grid, invalid-contract, exhaustive property, Python, and OpenCV precise-L2 tests
  • add native Criterion and paired OpenCV VGA/1080p/4K performance coverage
  • publish the algorithm and honest local accuracy/performance receipt in README, Pages, and notes

Why

SpatialRust had binary masks, contours, connected components, and morphology but no exact distance field. EDT is a reusable foundation for mask thickness, watershed seeds, contour distance, feather blending, and signed-distance workflows.

The implementation follows Felzenszwalb and Huttenlocher's separable lower-envelope algorithm and runs in O(width × height). A non-empty all-foreground mask is rejected because it has no finite nearest-background distance.

Measured impact

  • OpenCV correctness maximum error: 9.536743e-7 on the irregular case
  • canonical VGA/1080p/4K masks: exact values
  • native Criterion: 12.585 ms / 100.98 ms / 451.63 ms
  • Python median: 19.795 ms / 157.172 ms / 640.121 ms
  • OpenCV remains 10.60× / 12.63× / 12.35× faster on the recorded Windows host

Validation

  • cargo test -p spatialrust-vision --features full — 95 unit + 11 property tests
  • cargo test -p spatialrust-platform — 10 tests
  • cargo clippy -p spatialrust-vision --features dense --tests --bench dense -- -D warnings
  • cargo doc -p spatialrust-vision --features full --no-deps
  • cargo bench -p spatialrust-vision --features dense --bench dense -- --noplot
  • Python binding suite — 67 passed, 1 optional skip
  • mypy stubtest — pass
  • OpenCV correctness and performance reports — pass
  • comparison report contract — 8 tests

Workspace full Clippy still encounters the pre-existing spatialrust-camera manual-div-ceil lint before reaching this crate; the changed dense feature passes warnings-as-errors independently.

@rsasaki0109
rsasaki0109 merged commit 041e5d2 into main Jul 15, 2026
86 of 92 checks passed
@rsasaki0109
rsasaki0109 deleted the agent/exact-euclidean-distance-transform branch July 15, 2026 10:46
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