This function creates an object of class "im" representing
  a ‘pixel image’ or two-dimensional array of values.
The pixel grid is rectangular and occupies a rectangular window
  in the spatial coordinate system. 
  The pixel values are scalars: they can be real numbers, integers, 
  complex numbers, single characters or strings, 
  logical values, or categorical values. A pixel's
  value can also be NA, meaning that no value is defined
  at that location, and effectively that pixel is ‘outside’ the window. 
  Although the pixel values must be scalar,
  photographic colour images (i.e., with red, green, and blue brightness
  channels) can be represented as character-valued images in spatstat,
  using R's standard encoding of colours as character strings.
The matrix mat contains the ‘greyscale’ values
  for a rectangular grid of pixels.
  Note carefully that the entry mat[i,j]
  gives the pixel value at the location (xcol[j],yrow[i]).
  That is, the row index of the matrix mat corresponds
  to increasing y coordinate, while the column index of mat
  corresponds to increasing x coordinate.
  Thus yrow has one entry for each row of mat
  and xcol has one entry for each column of mat.
  Under the usual convention in R, a correct
  display of the image would be obtained by transposing the matrix, e.g.
  image.default(xcol, yrow, t(mat)), if you wanted to do it by hand.
The entries of mat may be numeric (real or integer), complex, 
  logical, character, or factor values.
  If mat is not a matrix, it will be converted into
  a matrix with nrow(mat) = length(yrow) and
  ncol(mat) = length(xcol).
  
To make a factor-valued image, note that 
  R has a quirky way of handling matrices with
  factor-valued entries. The command matrix cannot be used
  directly, because it destroys factor information.
  To make a factor-valued image, do one of the following:
- Create a - factorcontaining the pixel values,
    say- mat <- factor(.....), 
    and then assign matrix dimensions to it by- dim(mat) <- c(nr, nc)where- nr, ncare the numbers of rows and columns. The
    resulting object- matis both a factor and a vector.
 
- Supply - matas a one-dimensional factor
    and specify the arguments- xcoland- yrowto determine the dimensions of the image.
 
- Use the functions
    - cut.imor- eval.imto make factor-valued
    images from other images).
 
For a description of the methods available for pixel image objects,
  see im.object.
To convert other kinds of data to a pixel image (for example,
  functions or windows), use as.im.