Display a 2D image

Share:

Description

This function displays a 2D greyscale or RGB colour image. It is a wrapper around image, with more sensible defaults for images. It is (S3) generic. A method for 3D arrays is provided, which assumes that the third dimension corresponds to channel (grey/alpha for two channels, red/green/ blue for three, red/green/blue/alpha for four).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
display(x, ...)

## Default S3 method:
display(x, transpose = TRUE, useRaster = TRUE,
  add = FALSE, col = grey(0:255/255), ...)

## S3 method for class 'matrix'
display(x, ...)

## S3 method for class 'array'
display(x, max = 1, ...)

Arguments

x

An R object. For the default method, it must be coercible to a numeric matrix.

transpose

Whether to transpose the matrix before display. This is usually necessary due to the conventions of image.

useRaster

Whether to use raster graphics if possible. This is generally preferred for speed. Passed to image.

add

Whether to add the image to an existing plot. If TRUE, zero values in the image will be converted to NAs for plotting purposes, to make them transparent. This will not affect the original image data.

col

The colour scale to use. The default is 256 grey levels. The array method overrides this appropriately.

max

The maximum colour value for each channel. If the array has integer mode, this is fixed to 255. Passed to rgb.

...

Additional arguments to image, or the default method.

Details

Relative to the defaults for image (from the graphics package), this function transposes and then inverts the matrix along the y-direction, uses a grey colour scale, fills the entire device with the image, and tries to size the image correctly given the dot pitch of the display. Unfortunately the latter is not always possible, due to downstream limitations.

Value

This function is called for its side-effect of displaying an image on a new R device.

Author(s)

Jon Clayden <code@clayden.org>