# as.mask

##### Pixel Image Approximation of a Window

Obtain a discrete (pixel image) approximation of a given window

##### Usage

`as.mask(w, eps=NULL, dimyx=NULL, xy=NULL)`

##### Arguments

- w
- A window (object of class
`"owin"`

) or data acceptable to`as.owin`

. - eps
- (optional) width and height of pixels.
- dimyx
- (optional) pixel array dimensions
- xy
- (optional) pixel coordinates

##### Details

This function generates a rectangular grid of locations in the plane,
tests whether each of these locations lies inside the
window `w`

, and stores the results as a binary pixel image
or `mask' (an object of class `"owin"`

, see `owin.object`

).

The most common use of this function is to approximate the shape
of another window `w`

by a binary pixel image. In this case,
we will usually want to have a very fine grid of pixels.

This function can also be used to generate a coarsely-spaced grid of locations inside a window, for purposes such as subsampling and prediction.

The grid spacing and location are controlled by the
arguments `eps`

, `dimyx`

and `xy`

,
which are mutually incompatible.

If `eps`

is given, then it determines the grid spacing.
If `eps`

is a single number,
then the grid spacing will be approximately `eps`

in both the $x$ and $y$ directions. If `eps`

is a
vector of length 2, then the grid spacing will be approximately
`eps[1]`

in the $x$ direction and
`eps[2]`

in the $y$ direction.

If `dimyx`

is given, then the pixel grid will be an
$m \times n$ rectangular grid
where $m, n$ are given by `dimyx[2]`

, `dimyx[1]`

respectively. **Warning:** `dimyx[1]`

is the number of
pixels in the $y$ direction, and `dimyx[2]`

is the number
in the $x$ direction.

If `xy`

is given, then this should be a structure
containing two elements `x`

and `y`

which are the
vectors of $x$ and `y`

coordinates of the margins
of the grid. The pixel coordinates will be generated
from these two vectors. In this case `w`

may be omitted.
If neither `eps`

nor `dimyx`

nor `xy`

is given,
the pixel raster dimensions are obtained from
`spatstat.options("npixel")`

.

There is no inverse of this function. However, the function
`as.polygonal`

will compute a polygonal approximation
of a binary mask.

##### Value

- A window (object of class
`"owin"`

) of type`"mask"`

representing a binary pixel image.

##### See Also

##### Examples

```
w <- owin(c(0,10),c(0,10), poly=list(x=c(1,2,3,2,1), y=c(2,3,4,6,7)))
plot(w)
m <- as.mask(w)
plot(m)
x <- 1:9
y <- seq(0.25, 9.75, by=0.5)
m <- as.mask(w, xy=list(x=x, y=y))
```

*Documentation reproduced from package spatstat, version 1.24-1, License: GPL (>= 2)*