as.im(X, ...) ## S3 method for class 'im':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL)
## S3 method for class 'owin':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL, value=1)
## S3 method for class 'matrix':
as.im(X, W=NULL, \dots)
## S3 method for class 'tess':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL)
## S3 method for class 'function':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL, strict=FALSE)
## S3 method for class 'funxy':
as.im(X, W=Window(X), ...)
## S3 method for class 'distfun':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL)
## S3 method for class 'nnfun':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL)
## S3 method for class 'Smoothfun':
as.im(X, W=NULL, \dots)
## S3 method for class 'leverage.ppm':
as.im(X, \dots)
## S3 method for class 'data.frame':
as.im(X, \dots, step, fatal=TRUE, drop=TRUE)
## S3 method for class 'default':
as.im(X, W=NULL, \dots,
eps=NULL, dimyx=NULL, xy=NULL,
na.replace=NULL)
X
when X
is a function.NA
entries in the
output image.X
is a window.X
when X
is a function. If strict=FALSE
(the default), all the ...
arguments are passed to
X
. If strict=TRUE
fatal=TRUE
(the
default), an error occurs. If fatal=FALSE
, a warning is
issued and NULL
is returned.X
is a data frame with 3 columns. If drop=TRUE
(the default),
the result is a pixel image. If drop=FALSE
, the result is
a list containing one image."im"
),
or a list of pixel images,
or NULL
if the conversion failed.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:
"im"
."owin"
(seeowin.object
). The result is an image
with all pixel entries equal tovalue
inside the windowX
,
andNA
outside."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.W
(andNA
outside, unless the
argumentna.replace
is given).
ArgumentW
is required.function(x, y, ...)
which is to be evaluated to yield the image pixel values.
In this case, the additional argumentW
must be present.
This window will be converted to
a binary image mask. Then the functionX
will be evaluated
in the formX(x, y, ...)
wherex
andy
arevectorscontaining 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."funxy"
representing afunction(x,y,...)
"distfun"
representing a distance function
(created by the commanddistfun
)."nnfun"
representing a nearest neighbour function
(created by the commandnnfun
).x, y, z
in the format expected by
the standardR
functionsimage.default
andcontour.default
.
That is,z
is a matrix of pixel values,x
andy
are vectors of$x$and$y$coordinates respectively,
andz[i,j]
is the pixel value for the location(x[i],y[j])
."ppp"
).
See the separate documentation foras.im.ppp
.x
,y
andz
, if present,
will be assumed to contain the spatial coordinates and the pixel
values, respectively. Otherwise thex
andy
coordinates will be taken from the first two columns of the
data frame, and any remaining columns will be interpreted as
pixel values. 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)
eps
,dimyx
orxy
if present;W
, if it is
present and if it is a binary mask;X
if it is an image,
a binary mask, or alist(x,y,z)
;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.
If X
is a pixel image that was created by an older version
of X <- as.im(X)
will
repair the internal format of X
so that it conforms to the
current version of
If X
is a data frame with m
columns,
then m-2
columns of data are interpreted as pixel values,
yielding m-2
pixel images. The result of
as.im.data.frame
is a list of pixel
images, belonging to the class "imlist"
.
If m = 3
and drop=TRUE
(the default), then the
result is a pixel image rather than a list containing this image.
as.im.ppp
data(demopat)
# window object
W <- Window(demopat)
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)
# as.im.data.frame is the reverse of as.data.frame.im
grad <- bei.extra$grad
slopedata <- as.data.frame(grad)
slope <- as.im(slopedata)
unitname(slope) <- c("metre","metres")
all.equal(slope, grad) # TRUE
Run the code above in your browser using DataLab