Type: Package
Title: Convert Colour Specification to Colour Name
Version: 0.1-2
Author: Paul Murrell
Maintainer: Paul Murrell <paul@stat.auckland.ac.nz>
Description: Functions to convert an R colour specification to a colour name. The user can select and create different lists of colour names and different colour metrics for the conversion.
License: GPL-2 | GPL-3
Imports: grDevices, methods, parallel, colorspace
Suggests: grid, ggplot2, testthat
NeedsCompilation: no
Packaged: 2024-01-22 19:08:04 UTC; pmur002
Repository: CRAN
Date/Publication: 2024-01-22 20:00:08 UTC

Convert Colour Specification to Colour Name

Description

Functions to convert an R colour specification to a colour name. The user can select and create different lists of colour names and different colour metrics for the conversion.

Details

The DESCRIPTION file:

Package: roloc
Type: Package
Title: Convert Colour Specification to Colour Name
Version: 0.1-2
Author: Paul Murrell
Maintainer: Paul Murrell <paul@stat.auckland.ac.nz>
Description: Functions to convert an R colour specification to a colour name. The user can select and create different lists of colour names and different colour metrics for the conversion.
License: GPL-2 | GPL-3
Imports: grDevices, methods, parallel, colorspace
Suggests: grid, ggplot2, testthat

Index of help topics:

HTMLcolours             HTML colour names
NBScolours              ISCC-NBS colour dictionary
NgaTae                  Simple Maori Colour Names
Rcolours                The standard R colour names
ReseneColours           Resene colour dictionary
colourList              Define a list of colour names
colourMatch             Match Colour Specifications to Colour Names
colourName              Convert a colour specification to a colour name
colourSwatch            Colour Conversion Diagram
euclideanLUV            Euclidean colour metrics
roloc-package           Convert Colour Specification to Colour Name
simpleColours           Simple Colour Names

The main function in this package is colourName(), which takes one or more colour specifications and returns a matching colour name.

Author(s)

Paul Murrell

Maintainer: Paul Murrell <paul@stat.auckland.ac.nz>

References

Murrell, P. (2018). "Generating Colour Names: The 'roloc' Package for R." Technical Report 2018-01, Department of Statistics, The University of Auckland. https://www.stat.auckland.ac.nz/~paul/Reports/roloc/intro/roloc.html

See Also

colourName

Examples

colourName("#FF0000")

HTML colour names

Description

The list of HTML colour names

Usage

HTMLcolours

Format

A "colourList" object.

References

https://www.w3.org/TR/2011/REC-css3-color-20110607/#html4


ISCC-NBS colour dictionary

Description

The ISCC-NBS list of colour names

Usage

NBScolours

Format

A "colourList" object.

Warning

Some of the sRGB centroids are approximations because some ISCC-NBS colours cannot be represented within the sRGB gamut. This means that some ISCC-NBS colour names will not “round trip”; the sRGB centroid will not return the ISCC-NBS colour name.

Source

http://people.csail.mit.edu/jaffer/Color/NBS-ISCC-rgb.txt

References

http://tx4.us/nbs-iscc.htm http://www.munsellcolourscienceforpainters.com/ColourSciencePapers/sRGBCentroidsForTheISCCNBSColourSystem.pdf


Simple Maori Colour Names

Description

A small set of Maori colour names.

Usage

NgaTae

Format

A "colourList" object.

References

http://www.maori.org.nz/kotereo/default.php?pid=sp148&parent=115


The standard R colour names

Description

The list of colour names that R recognises as colour specifications. This list can also be referred to as X11colours or CSScolours or SVGcolours.

Usage

Rcolours

Format

A "colourList" object.

References

Jaffer, A. (2018). Color-name dictionaries. http://people.csail.mit.edu/jaffer/Color/Dictionaries#X11. Accessed: 2018-01-24.


Resene colour dictionary

Description

The Resene list of colour names

Usage

ReseneColours

Format

A "colourList" object.

Source

http://people.csail.mit.edu/jaffer/Color/Resene-X11

References

Jaffer, A. (2018). Color-name dictionaries. http://people.csail.mit.edu/jaffer/Color/Dictionaries#X11. Accessed: 2018-01-24.


Define a list of colour names

Description

Define a list of colour names, which includes both colour names and a set of sRGB specifications corresponding to the names.

Usage

colourList(names, colours)
colorList(names, colours)

Arguments

names

A character vector of colour names.

colours

An "sRGB" colour object (which provides the sRGB specifications corresponding to the colour names).

Value

A "colourList" object.

Author(s)

Paul Murrell

Examples

colourList("red", colorspace::RGB(1, 0, 0))

Match Colour Specifications to Colour Names

Description

Compare colour specifications to a list of colour names and return distance information for each comparison.

Usage

colourMatch(colour, colourList, colourMetric, ...)

Arguments

colour

An R colour specification

colourList

A list of colours

colourMetric

A colour metric function. See the Details Section.

...

Arguments passed to the colour metric function.

Details

The colour metric function must take at least two arguments, both of which are "RGB" colour objects (as created by funcions in the colorspace package such as RGB): colour, which is the colour specification to find a match for; and colourList, which represents the list of colour names to find a match within. Any additional arguments must have default values (so that they do not HAVE to be specified in a call to colourName). The colour metric function must return either a vector or a list, the same length as the colour argument, containing integer indices into the colour list. NA means the colour could not be represented in the colour space used by the colour metric. "unknown" means that the colour

Value

A "colourMatch" object with components for the original colour specification, the original colour list object, and a matric of distances between each colour specification and each colour name in the colour list.

Author(s)

Paul Murrell

See Also

This function underlies both colourName and colourSwatch.

Examples

colourMatch("red", colourList=HTMLcolours)

Convert a colour specification to a colour name

Description

Return a colour name from a colour specification.

Usage

## S3 method for class 'colourMatch'
colourNames(x,
                             ...)
## Default S3 method:
colourNames(x,
                             colourList=getOption("roloc.colourList"),
                             colourMetric=getOption("roloc.colourMetric"),
                             ...)
colourName(...)

Arguments

x

A "colourMatch" object or an R colour specification

colourList

A list of colours

colourMetric

A colour metric function. See colourMatch for details.

...

For colourNames, arguments passed to the colour metric function. For colourName, arguments passed to colourNames

Value

colourNames returns a list of colour names (possibly more than one per colour specification). colourName returns a vector of colour names (only the first match per colour specification).

Author(s)

Paul Murrell

Examples

# Some colours() are identical to each other
newColours <- colourName(rgb(t(col2rgb(colours())), maxColorValue=255))
repeats <- newColours != colours()
cbind(colours()[repeats], newColours[repeats])

Colour Conversion Diagram

Description

Draw a diagram of a colour conversion with four columns: original colour specification, plus swatch, matching colour name, plus swatch. colourSwatches can show multiple matches per colour specification.

Usage

colourSwatch(x, ..., newpage = TRUE)
## S3 method for class 'colourMatch'
colourSwatch(x, ..., newpage = TRUE)
## Default S3 method:
colourSwatch(x,
                               colourList=getOption("roloc.colourList"),
                               colourMetric=getOption("roloc.colourMetric"),
                               ..., newpage = TRUE)
colourSwatches(x, ..., newpage = TRUE)
## S3 method for class 'colourMatch'
colourSwatches(x, ..., newpage = TRUE)
## Default S3 method:
colourSwatches(x,
                               colourList=getOption("roloc.colourList"),
                               colourMetric=getOption("roloc.colourMetric"),
                               ..., newpage = TRUE)

Arguments

x

A "colourMatch" object or an R colour specification

colourList

A list of colours

colourMetric

A colour metric function. See colourMatch for details.

...

Arguments passed to the colour metric function.

newpage

Whether to start a new page on the current graphics device.

Value

These functions are used for their side-effect (a colour match diagram).

Author(s)

Paul Murrell

Examples

colourSwatch("red")

Euclidean colour metrics

Description

Colour metrics that calculate euclidean distance between colours in different colour spaces.

Usage

euclideanLUV(colour, colourList, tolerance = Inf)
euclideanRGB(colour, colourList, tolerance = Inf)
euclideanDistance(spec, list, tolerance) 

Arguments

colour

An "sRGB" colour object representing colours to find a match for.

colourList

An "sRGB" colour object representing a list of colours to find a match within.

tolerance

A numeric value indicating a range beyond which matches will not be accepted.

spec

A single colour specification, as an RGB vector of three values.

list

A list of colours, as an RGB matrix with three columns.

Details

euclideanLUV() calculates euclidean distance in the CIE Luv colour space.

euclideanRGB() calculates euclidean distance in the sRGB colour space.

euclideanDistance() is provided as a helper for defining euclidean metrics in other colour spaces.

Value

The colour metrics return a matrix of distances, with one row per colour specification and one column per colour name.

Author(s)

Paul Murrell


Simple Colour Names

Description

A set of colour names with descriptive labels that are evenly spaced throughout CIE LUV space.

Usage

simpleColours

Format

A "colourList" object.