https://github.com/cran/spatstat
Tip revision: 23e1475a0cfda7d9e75ab7ecd3fc362533582402 authored by Adrian Baddeley on 16 December 2008, 00:00:00 UTC
version 1.14-9
version 1.14-9
Tip revision: 23e1475
eval.im.Rd
\name{eval.im}
\alias{eval.im}
\title{Evaluate Expression Involving Pixel Images}
\description{
Evaluates any expression involving one or more pixel images,
and returns a pixel image.
}
\usage{
eval.im(expr, envir)
}
\arguments{
\item{expr}{An expression.}
\item{envir}{Optional. The environment in which to evaluate the expression.}
}
\details{
This function is a wrapper to make it easier to perform
pixel-by-pixel calculations in an image.
Pixel images in \pkg{spatstat}
are represented by objects of class \code{"im"}
(see \code{\link{im.object}}). These are essentially matrices of
pixel values, with extra attributes recording the pixel dimensions,
etc.
Suppose \code{X} is a pixel image. Then \code{eval.im(X+3)}
will add 3 to the value of every pixel in \code{X}, and return
the resulting pixel image.
Suppose \code{X} and \code{Y} are two pixel images with compatible
dimensions: they have the same number of pixels, the same physical
size of pixels, and the same bounding box. Then
\code{eval.im(X + Y)} will add the corresponding pixel values in
\code{X} and \code{Y}, and return the resulting pixel image.
In general, \code{expr} can be any expression in the R language involving
(a) the \emph{names} of pixel images, (b) scalar
constants, and (c) functions which are vectorised.
See the Examples.
First \code{eval.im} determines which of the \emph{variable names}
in the expression \code{expr} refer to pixel images. Each such name
is replaced by a matrix containing the pixel values. The expression is
then evaluated. The result should be a matrix; it is taken as
the matrix of pixel values.
The expression \code{expr} must be vectorised.
There must be at least one pixel image in the expression.
All images must have compatible dimensions.
}
\value{
An image object of class \code{"im"}.
}
\seealso{
\code{\link{as.im}},
\code{\link{compatible.im}},
\code{\link{im.object}}
}
\examples{
# test images
X <- as.im(function(x,y) { x^2 - y^2 }, unit.square())
Y <- as.im(function(x,y) { 3 * x + y }, unit.square())
eval.im(X + 3)
eval.im(X - Y)
eval.im(abs(X - Y))
Z <- eval.im(sin(X * pi) + Y)
}
\author{Adrian Baddeley
\email{adrian@maths.uwa.edu.au}
\url{http://www.maths.uwa.edu.au/~adrian/}
and Rolf Turner
\email{r.turner@auckland.ac.nz}
}
\keyword{spatial}
\keyword{manip}
\keyword{programming}