spatstat (version 1.52-1)

im.object: Class of Images


A class "im" to represent a two-dimensional pixel image.



The internal representation of images is likely to change in future releases of spatstat. Do not address the entries in an image directly. To extract all pixel values from an image object, use


An object of this class represents a two-dimensional pixel image. It specifies

  • the dimensions of the rectangular array of pixels

  • \(x\) and \(y\) coordinates for the pixels

  • a numeric value (``grey value'') at each pixel

If X is an object of type im, it contains the following elements:

v matrix of values
dim dimensions of matrix v
xrange range of \(x\) coordinates of image window
yrange range of \(y\) coordinates of image window
xstep width of one pixel
ystep height of one pixel
xcol vector of \(x\) coordinates of centres of pixels

Users are strongly advised not to manipulate these entries directly.

Objects of class "im" may be created by the functions im and Image objects are also returned by various functions including distmap, Kmeasure, setcov, and

Image objects may be displayed using the methods,, and There are also methods for printing information about an image, for summarising an image, for calculating the average pixel value, for plotting a histogram of pixel values, for calculating quantiles of pixel values, and for dividing the range of pixel values into categories.

Pixel values in an image may be extracted using the subset operator [.im. To extract all pixel values from an image object, use The levels of a factor-valued image can be extracted and changed with levels and levels<-.

Calculations involving one or more images (for example, squaring all the pixel values in an image, converting numbers to factor levels, or subtracting one image from another) can often be done easily using To find all pixels satisfying a certain constraint, use solutionset.

Note carefully that the entry v[i,j] gives the pixel value at the location (xcol[j],yrow[i]. That is, the row index of the matrix v 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 v and xcol has one entry for each column of v. 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(v)), if you wanted to do it by hand.

See Also

im,,,,, [.im