as.im {spatstat} | R Documentation |
Converts various kinds of data to a pixel image
as.im(X, W, ...)
X |
Data to be converted to a pixel image. |
W |
Window object required when X is a function. |
... |
Additional arguments passed to X when X
is a function. |
This function converts the data x
into a pixel image
object of class "im"
(see im.object
).
Currently X
may be any of the following:
"im"
. This object is just returned.
"owin"
(see owin.object
).
This window is first converted to a binary image mask
by as.mask
. Then the pixel entries
TRUE
and FALSE
are converted to
1
and NA
respectively.
The result is returned as an object of class "im"
.
function(x, y, ...)
which is to be evaluated to yield the image pixel values.
In this case, the additional argument W
must be
a window object. This window will be converted to
a binary image mask. Then the function X
will be evaluated
in the form X(x, y, ...)
where x
and y
are
vectors containing the x and y coordinates
of all the pixels in the image mask. This must return a numeric vector
of the same length as the input vectors, giving the pixel values.
win
.
x, y, z
in the format expected by
the standard R
functions
contour.default
and image.default
.
That is, z
is a matrix of pixel values, x
and y
are vectors of x and y coordinates respectively,
and z[i,j]
is the pixel value for the location
(x[i],y[j])
.
An image object of class "im"
.
Adrian Baddeley adrian@maths.uwa.edu.au http://www.maths.uwa.edu.au/~adrian/ and Rolf Turner rolf@math.unb.ca http://www.math.unb.ca/~rolf
data(demopat) # window object W <- demopat$window plot(W) Z <- as.im(W) image(Z) # function Z <- as.im(function(x,y) {x^2 + y^2}, unit.square()) image(Z) # function with extra arguments f <- function(x, y, x0, y0) { sqrt((x - x0)^2 + (y-y0)^2) } Z <- as.im(f, unit.square(), x0=0.5, y0=0.5) image(Z) # Revisit the Sixties data(letterR) Z <- as.im(f, letterR, x0=2.5, y0=2) image(Z) # usual convention in S stuff <- list(x=1:10, y=1:10, z=matrix(1:100, nrow=10)) Z <- as.im(stuff)