Computes the distances from each pixel in a window to the boundary of the window.
bdist.pixels(w, ..., style=c("image", "matrix", "coords"), method=c("C", "interpreted"))
A window (object of class
Arguments passed to
Character string (partially matched) determining the format of
the output: either
Choice of algorithm to use when
This function computes, for each pixel
u in the
Frame containing the window
w, the shortest distance
d(u, w^c) from
u to the complement of
w. This value is zero for pixels lying outside
and is positive for pixels inside
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
If the window is a rectangle or a polygonal region,
the grid of pixels is determined by the arguments
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
w is a polygon: the default is
which is much faster than
To compute the distance from each pixel to the bounding rectangular frame
style="image", a pixel image (object of class
containing the distances from each pixel in the image raster
to the boundary of the window.
a matrix giving the distances.
Rows of this matrix correspond to
y coordinate and columns to the
style="coords", a list with three components
x,y are vectors of length
y coordinates respectively,
z is an
m \times 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
This result can be plotted with
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 opa <- par(mfrow=c(1,2)) plot(bdist.pixels(letterR)) plot(framedist.pixels(letterR)) par(opa)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.