distanceTransform
calculates the distance to the closest
zero pixel for each pixel of the source image.
Arguments
- image
An
Image
object.- distance_type
A character string indicating the type of distance to be calculated. It can be any of the following:
- "L1" (the default):
distance = |x1-x2| + |y1-y2|
.- "L2":
the simple euclidean distance.
- "C":
distance = max(|x1-x2|,|y1-y2|)
.- "L12":
L1-L2 metric.
distance = 2(sqrt(1+x*x/2) - 1))
.- "FAIR":
distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998
.- "WELSCH":
distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846
.- "HUBER":
distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345
.
- mask_size
A numeric value indicating the size of the distance transform mask. It can be any of the following:
- 0:
used only to indicate the Felzenszwalb algorithm when
distance_type = "L2"
.- 3 (the default):
3x3 mask.
- 5:
5x5 mask.
- target
The location where the results should be stored. It can take 3 values:
- "new":
a new
Image
object is created and the results are stored inside (the default).- "self":
the results are stored back into
image
(faster but destructive).- An
Image
object: the results are stored in another existing
Image
object. This is fast and will not replace the content ofimage
but will replace that oftarget
. Note thattarget
must have the same dimensions asimage
, must have a single channel, and its bit depth must be either "8U" or "32F".
Value
If target="new"
, the function returns an Image
object. If target="self"
, the function returns nothing and modifies
image
in place. If target
is an Image
object,
the function returns nothing and modifies that Image
object in
place.
An Image
object.
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
changeColorSpace(balloon, "GRAY", target = "self")
#> NULL
bin <- balloon < 200
dst <- distanceTransform(bin)