The Euclidean distance transform produces an array like its argument, but with element values representing the Euclidean distance to the nearest nonzero element. The input is treated as logically binary, with all nonzero values treated as "on", and all zeroes as "off".
distanceTransform(x, ...)
# S3 method for default
distanceTransform(x, pixdim = TRUE, signed = FALSE, ...)
x | Any object. For the default method, this must be coercible to an array. |
---|---|
... | Additional arguments to methods. |
pixdim | An optional numeric vector or logical value. In the former
case it will be taken as giving the physical size of the array elements of
|
signed | Logical value. If |
An array of the same dimension as the original, whose elements give the Euclidean distance from that element to the nearest "on" element in the original.
This implementation is based on the "marching parabolas" algorithm described by Felzenszwalb and Huttenlocher in the paper below.
P.F. Felzenszwalb & D.P. Huttenlocher (2012). Distance transforms of sampled functions. Theory of Computing 8(19):415-428.
Jon Clayden <code@clayden.org>
x <- c(0,0,1,0,0,0,1,1,1,0,0)
distanceTransform(x)
#> [1] 2 1 0 1 2 1 0 0 0 1 2
distanceTransform(x, pixdim=2)
#> [1] 4 2 0 2 4 2 0 0 0 2 4