Skip to main content

distance_transform

Function distance_transform 

Source
pub fn distance_transform(input: &Tensor) -> Result<Tensor, ImgProcError>
Expand description

Euclidean distance transform. Input: [H, W] binary f32. L1 distance transform on a binary single-channel [H, W, 1] image.

Input pixels > 0.5 are foreground. Output is the distance from each foreground pixel to the nearest background pixel (two-pass L1).

Uses SIMD (NEON/SSE) to accelerate the vertical propagation step, which processes 4 f32 values at a time. L1 Manhattan distance transform. Two interleaved passes (like OpenCV): each pass handles both vertical (SIMD) and horizontal (scalar) in one sweep. Conditional stores skip writes when value unchanged (huge win on sparse inputs).