Learn R Programming

spatstat.geom (version 3.3-2)

transmat: Convert Pixel Array Between Different Conventions

Description

This function provides a simple way to convert arrays of pixel data between different display conventions.

Usage

transmat(m, from, to)

Value

Another matrix obtained by rearranging the entries of m.

Arguments

m

A matrix.

from,to

Specifications of the spatial arrangement of the pixels. See Details.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au

Rolf Turner rolfturner@posteo.net

and Ege Rubak rubak@math.aau.dk

Details

Pixel images are handled by many different software packages. In virtually all of these, the pixel values are stored in a matrix, and are accessed using the row and column indices of the matrix. However, different pieces of software use different conventions for mapping the matrix indices \([i,j]\) to the spatial coordinates \((x,y)\).

  • In the Cartesian convention, the first matrix index \(i\) is associated with the first Cartesian coordinate \(x\), and \(j\) is associated with \(y\). This convention is used in image.default.

  • In the European reading order convention, a matrix is displayed in the spatial coordinate system as it would be printed in a page of text: \(i\) is effectively associated with the negative \(y\) coordinate, and \(j\) is associated with \(x\). This convention is used in some image file formats.

  • In the spatstat convention, \(i\) is associated with the increasing \(y\) coordinate, and \(j\) is associated with \(x\). This is also used in some image file formats.

To convert between these conventions, use the function transmat. If a matrix m contains pixel image data that is correctly displayed by software that uses the Cartesian convention, and we wish to convert it to the European reading convention, we can type mm <- transmat(m, from="Cartesian", to="European"). The transformed matrix mm will then be correctly displayed by software that uses the European convention.

Each of the arguments from and to can be one of the names "Cartesian", "European" or "spatstat" (partially matched) or it can be a list specifying another convention. For example to=list(x="-i", y="-j")! specifies that rows of the output matrix are expected to be displayed as vertical columns in the plot, starting at the right side of the plot, as in the traditional Chinese, Japanese and Korean writing order.

Examples

Run this code
  opa <- par(mfrow=c(1,2))
  # image in spatstat format
  Z <- bei.extra$elev
  plot(Z, main="plot.im", ribbon=FALSE)
  m <- as.matrix(Z)
  # convert matrix to format suitable for display by image.default
  Y <- transmat(m, from="spatstat", to="Cartesian")
  image(Y, asp=0.5, main="image.default", axes=FALSE)
  par(opa)

Run the code above in your browser using DataLab