Learn R Programming

Rvision (version 0.4.2)

distanceTransform: Distance Transform

Description

distanceTransform calculates the distance to the closest zero pixel for each pixel of the source image.

Usage

distanceTransform(image, distance_type = "L1", mask_size = 3)

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.

Value

An Image object.

Examples

Run this code
# NOT RUN {
file <- system.file("sample_img/balloon1.png", package = "Rvision")
balloon <- image(file)
changeColorSpace(balloon, "GRAY", in_place = TRUE)
bin <- balloon < 200
dst <- distanceTransform(bin)
plot(dst * round(65536 / 255))

# }

Run the code above in your browser using DataLab