Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

distmap.owin

Distance Map of Window


Description

Computes the distance from each pixel to the nearest point in the given window.

Usage

## S3 method for class 'owin'
distmap(X, ..., discretise=FALSE, invert=FALSE)

Arguments

X

A window (object of class "owin").

...

Arguments passed to as.mask to control pixel resolution.

discretise

Logical flag controlling the choice of algorithm when X is a polygonal window. See Details.

invert

If TRUE, compute the distance transform of the complement of the window.

Details

The “distance map” of a window W is the function f whose value f(u) is defined for any two-dimensional location u as the shortest distance from u to W.

This function computes the distance map of the window X and returns the distance map as a pixel image. The greyscale value at a pixel u equals the distance from u to the nearest pixel in X.

Additionally, the return value has an attribute "bdry" which is also a pixel image. The grey values in "bdry" give the distance from each pixel to the bounding rectangle of the image.

If X is a binary pixel mask, the distance values computed are not the usual Euclidean distances. Instead the distance between two pixels is measured by the length of the shortest path connecting the two pixels. A path is a series of steps between neighbouring pixels (each pixel has 8 neighbours). This is the standard ‘distance transform’ algorithm of image processing (Rosenfeld and Kak, 1968; Borgefors, 1986).

If X is a polygonal window, then exact Euclidean distances will be computed if discretise=FALSE. If discretise=TRUE then the window will first be converted to a binary pixel mask and the discrete path distances will be computed.

The arguments ... are passed to as.mask to control the pixel resolution.

This function is a method for the generic distmap.

Value

A pixel image (object of class "im") whose greyscale values are the values of the distance map. The return value has an attribute "bdry" which is a pixel image.

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

References

Borgefors, G. Distance transformations in digital images. Computer Vision, Graphics and Image Processing 34 (1986) 344–371.

Rosenfeld, A. and Pfalz, J.L. Distance functions on digital pictures. Pattern Recognition 1 (1968) 33-61.

See Also

Examples

U <- distmap(letterR)
  if(interactive()) {
  plot(U)
  plot(attr(U, "bdry"))
  }

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.