as.im {spatstat} | R Documentation |
Converts various kinds of data to a pixel image
as.im(X, ...) ## S3 method for class 'im' as.im(X, W=NULL, ..., eps=NULL, dimyx=NULL, xy=NULL, na.replace=NULL) ## S3 method for class 'owin' as.im(X, W=NULL, ..., eps=NULL, dimyx=NULL, xy=NULL, na.replace=NULL, value=1) ## S3 method for class 'matrix' as.im(X, W=NULL, ...) ## S3 method for class 'tess' as.im(X, W=NULL, ..., eps=NULL, dimyx=NULL, xy=NULL, na.replace=NULL) ## S3 method for class 'function' as.im(X, W=NULL, ..., eps=NULL, dimyx=NULL, xy=NULL, na.replace=NULL) ## S3 method for class 'distfun' as.im(X, W=NULL, ..., eps=NULL, dimyx=NULL, xy=NULL, na.replace=NULL) ## S3 method for class 'leverage.ppm' as.im(X, ...) ## Default S3 method: as.im(X, W=NULL, ..., eps=NULL, dimyx=NULL, xy=NULL, na.replace=NULL)
X |
Data to be converted to a pixel image. |
W |
Window object which determines the spatial domain and pixel array geometry. |
... |
Additional arguments passed to |
eps,dimyx,xy |
Optional parameters passed to |
na.replace |
Optional value to replace |
value |
Optional.
The value to be assigned to pixels inside the window,
if |
This function converts the data X
into a pixel image
object of class "im"
(see im.object
).
The function as.im
is generic, with methods for the classes
listed above.
Currently X
may be any of the following:
a pixel image object, of class "im"
.
a window object, of class "owin"
(see
owin.object
). The result is an image
with all pixel entries equal to value
inside the window X
,
and NA
outside.
a matrix.
a tessellation (object of class "tess"
).
The result is a factor-valued image, with one factor level
corresponding to each tile of the tessellation. Pixels are classified
according to the tile of the tessellation into which they fall.
a single number (or a single logical, complex, factor or character
value). The result is an image
with all pixel entries equal to this constant value
inside the window W
(and NA
outside, unless the
argument na.replace
is given).
Argument W
is required.
a function of the form function(x, y, ...)
which is to be evaluated to yield the image pixel values.
In this case, the additional argument W
must be present.
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, and ...
are any extra
arguments given. This function must return a
vector or factor of the same length as the input vectors,
giving the pixel values.
an object of class "distfun"
representing a distance function
(created by the command distfun
).
a list with entries x, y, z
in the format expected by
the standard R
functions
image.default
and contour.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])
.
a point pattern (object of class "ppp"
).
See the separate documentation for as.im.ppp
.
The spatial domain (enclosing rectangle) of the pixel image
is determined by the argument W
. If W
is absent,
the spatial domain is determined by X
.
When X
is a function, a matrix, or a single numerical value,
W
is required.
The pixel array dimensions of the final resulting image are determined by (in priority order)
the argument eps
, dimyx
or xy
if present;
the pixel dimensions of the window W
, if it is
present and if it is a binary mask;
the pixel dimensions of X
if it is an image,
a binary mask, or a list(x,y,z)
;
the default pixel dimensions,
controlled by spatstat.options
.
Note that if eps
, dimyx
or xy
is given, this will override
the pixel dimensions of X
if it has them.
Thus, as.im
can be used to change an image's pixel dimensions.
If the argument na.replace
is given, then all NA
entries
in the image will be replaced by this value. The resulting image is
then defined everwhere on the full rectangular domain, instead of a
smaller window. Here na.replace
should be a single value,
of the same type as the other entries in the image.
An image object of class "im"
.
Adrian Baddeley Adrian.Baddeley@csiro.au http://www.maths.uwa.edu.au/~adrian/ and Rolf Turner r.turner@auckland.ac.nz
Separate documentation for as.im.ppp
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) # convert to finer grid Z <- as.im(Z, dimyx=256) # pixellate the Dirichlet tessellation Di <- dirichlet(runifpoint(10)) plot(as.im(Di)) plot(Di, add=TRUE)