display: Display a 2D image

displayR Documentation

Display a 2D image

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

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 = NULL, ...)

Arguments

x

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

...

Additional arguments to image, or the default method.

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 NULL, the default, this is taken from the "range" attribute, if there is one, otherwise it is 255 for integer-mode arrays, and 1 otherwise. Passed to rgb.

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.

If x has attributes "range", "background", "asp" or "dpi", these are respected.

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>


mmand documentation built on Feb. 16, 2023, 9:22 p.m.