Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rgbArray

RGB arrays


Description

The rgbArray function constructs an integer array whose values are byte-packed representations of 8-bit RGBA colour values. The channels attribute (with value 3 or 4) indicates how many channels are being used. The resulting array can be used to construct an RGB(A) NIfTI image, or converted to standard R colour strings using the as.character method.

Usage

rgbArray(red, green, blue, alpha, max = NULL, dim = NULL, ...)

## S3 method for class 'rgbArray'
as.character(x, flatten = TRUE, ...)

Arguments

red

A numeric vector (or array) of red channel values. If this is the only channel argument, it can also be a character vector of colour values (including alpha, if required), or a numeric array whose last dimension is 2 (for grey + alpha), 3 (for RGB) or 4 (for RGBA).

green, blue, alpha

Numeric vectors (or arrays) containing values for the appropriate channel. These will be combined with the red values using cbind, and hence recycled as necessary. Alpha, or green and blue, can be missing.

max

The maximum possible value for any channel. The default is 255 when the data is of integer mode, and 1 otherwise. Values above this, or below zero, will be clipped to the appropriate extreme.

dim

An integer vector of dimensions for the final array. The dimensions of red are used if this is NULL.

...

For rgbArray, additional attributes to set on the result, such as pixdim. These are passed directly to structure. For the as.character method, this argument is ignored.

x

An rgbArray object.

flatten

Logical value. If FALSE, the dimensions of x will be retained in the result. The default is TRUE, for consistency with the usual behaviour of as.character, which strips all attributes.

Value

rgbArray returns an integer-mode array of class "rgbArray". The as.character method returns a character-mode vector of colour strings.

Note

The values of an "rgbArray" are not easily interpreted, and may depend on the endianness of the platform. For manipulation or use as colours they should generally be converted to character mode, or the channels extracted using the channels function.

Author(s)

Jon Clayden <code@clayden.org>


RNifti

Fast R and C++ Access to NIfTI Images

v1.3.0
GPL-2
Authors
Jon Clayden [cre, aut] (<https://orcid.org/0000-0002-6608-0619>), Bob Cox [aut], Mark Jenkinson [aut], Matt Hall [ctb], Rick Reynolds [ctb], Kate Fissell [ctb], Jean-loup Gailly [cph], Mark Adler [cph]
Initial release
2020-12-04

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.