Learn R Programming

vectools (version 0.3.0)

86_color_transformations: Color Conversion

Description

Functions to map vectors/matrices/arrays of colors between color spaces.

THESE FUNCTIONS REQUIRE THE colorspace PACKAGE TO BE INSTALLED AND LOADED.

One exception to this requirement is mapping numeric values to strings, if the "from" color space equals the "to" color space.

Usage

mapcol (colv, …, as.list = is.list(colv), as.string=FALSE,
    from="sRGB", to=from, correction=TRUE)
mapcol3 (x, y, z, alpha, …, as.list=FALSE, as.string=FALSE,
    from="sRGB", to=from, correction=TRUE)

Arguments

colv

A numeric array with two or more dimensions. (Such as the result of standardize.cols with as.array=TRUE. The last dimension should have three or four levels, which represent channels.

x, y, z, alpha

Numeric vectors. Alternative way of specifying color.

as.list, as.string

Logical, if true, return a list or string, see value section.

from

String, the input color space.

to

String, the output color space. Ignored, if as.string is true.

correction

Logical, correct the sRGB values. Ignored, unless converting HCL to sRGB.

Ignored.

Value

By default, these functions return arrays. Where the last dimension corresponds to channel.

If as.string is true, a character vector/matrix/array is returned. If as.list is true, a list is returned, with one element per channel.

Details

The functions wrap functions from the colorspace package.

The to and from arguments, use names of color spaces from the colorspace package.

This includes: "XYZ", "RGB", "sRGB", "LAB", "polarLAB", "HSV", "HLS", "LUV" and "polarLUV".

In addition to HCL, with is the same as polarLUV, but the the arguments in a different order.

The same labels are used for three channel and four channel images.

See Also

standardize.cols

Examples

Run this code
# NOT RUN {
library (colorspace)

cols <- standardize.cols (
    c ("black", "white", "#000000", "#FFFFFF"),
    as.array=TRUE)

#hues
mapcol (cols, to="HCL")[,1]
# }

Run the code above in your browser using DataLab