distmap.psp | R Documentation |
Computes the distance from each pixel to the nearest line segment in the given line segment pattern.
## S3 method for class 'psp'
distmap(X, ..., extras=TRUE, clip=FALSE, metric=NULL)
X |
A line segment pattern (object of class |
... |
Arguments passed to |
extras |
Logical value specifying whether to compute the
additional attributes |
clip |
Logical value specifying whether the resulting pixel image
should be clipped to the window of |
metric |
Optional. A distance metric
(object of class |
The “distance map” of a line segment pattern X
is the function
f
whose value f(u)
is defined for any two-dimensional
location u
as the shortest distance from u
to X
.
This function computes the distance map of the line segment pattern 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 line segment of the pattern X
.
Distances are computed using analytic geometry.
The result is a pixel image.
If clip=FALSE
(the default), the pixel values are defined at every pixel in
the rectangle Frame(X)
. If clip=TRUE
, the pixel values are defined
only inside Window(X)
, and are NA
outside this window.
Computation is faster when clip=FALSE
.
Additionally, if extras=TRUE
, the return value
has two attributes, "index"
and "bdry"
, which are
also pixel images. The pixels values of "bdry"
give the
distance from each pixel to the boundary of the window of X
(and are zero outside this window).
The pixel values of "index"
are integers identifying which
line segment of X
is closest.
If clip=FALSE
(the default), these images are defined at every pixel
in Frame(X)
; if clip=TRUE
, they are clipped to the window of X
.
Computation is faster when extras=FALSE
.
This is a method for the generic function distmap
.
Note that this function gives the exact distance from the
centre of each pixel to the nearest line segment.
To compute the exact distance from the points in a point pattern
to the nearest line segment, use distfun
or one of the
low-level functions nncross
or project2segment
.
A pixel image (object of class "im"
) whose greyscale values
are the values of the distance map.
The return value has attributes "index"
and "bdry"
which are also pixel images.
.
distmap
,
distmap.owin
,
distmap.ppp
,
distfun
,
nncross
,
nearestsegment
,
project2segment
.
a <- psp(runif(20),runif(20),runif(20),runif(20), window=owin())
Z <- distmap(a)
plot(Z)
plot(a, add=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.