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

bdist.pixels

Distance to Boundary of Window


Description

Computes the distances from each pixel in a window to the boundary of the window.

Usage

bdist.pixels(w, ..., style="image", method=c("C", "interpreted"))

Arguments

w

A window (object of class "owin").

...

Arguments passed to as.mask to determine the pixel resolution.

style

Character string determining the format of the output: either "matrix", "coords" or "image".

method

Choice of algorithm to use when w is polygonal.

Details

This function computes, for each pixel u in the window w, the shortest distance dist(u, W') from u to the boundary of W.

If the window is a binary mask then the distance from each pixel to the boundary is computed using the distance transform algorithm distmap.owin. The result is equivalent to distmap(W, invert=TRUE).

If the window is a rectangle or a polygonal region, the grid of pixels is determined by the arguments "\dots" passed to as.mask. The distance from each pixel to the boundary is calculated exactly, using analytic geometry. This is slower but more accurate than in the case of a binary mask.

For software testing purposes, there are two implementations available when w is a polygon: the default is method="C" which is much faster than method="interpreted".

Value

If style="image", a pixel image (object of class "im") containing the distances from each pixel in the image raster to the boundary of the window.

If style="matrix", a matrix giving the distances from each pixel in the image raster to the boundary of the window. Rows of this matrix correspond to the y coordinate and columns to the x coordinate.

If style="coords", a list with three components x,y,z, where x,y are vectors of length m,n giving the x and y coordinates respectively, and z is an m x n matrix such that z[i,j] is the distance from (x[i],y[j]) to the boundary of the window. Rows of this matrix correspond to the x coordinate and columns to the y coordinate. This result can be plotted with persp, image or contour.

Author(s)

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

See Also

Examples

u <- owin(c(0,1),c(0,1))
  d <- bdist.pixels(u, eps=0.01)
  image(d)
  d <- bdist.pixels(u, eps=0.01, style="matrix")
  mean(d >= 0.1)
  # value is approx (1 - 2 * 0.1)^2 = 0.64

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.