spatstat (version 1.7-11)

as.im: Convert to Pixel Image

Description

Converts various kinds of data to a pixel image

Usage

as.im(X, W, ...)

Arguments

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.

Value

  • An image object of class "im".

Details

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:

  • a pixel image object, of class"im". This object is just returned.
  • a window object, of class"owin"(seeowin.object). This window is first converted to a binary image mask byas.mask. Then the pixel entriesTRUEandFALSEare converted to1andNArespectively. The result is returned as an object of class"im".
  • a function of the formfunction(x, y, ...)which is to be evaluated to yield the image pixel values. In this case, the additional argumentWmust be a window object. This window will be converted to a binary image mask. Then the functionXwill be evaluated in the formX(x, y, ...)wherexandyarevectorscontaining 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.
  • a single numerical value. The result is an image with pixel entries equal to this numerical value inside the imagewin.

Examples

Run this code
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)

Run the code above in your browser using DataCamp Workspace