distance: Colour distance and contrast

distanceR Documentation

Colour distance and contrast

Description

The distance() function calculates a distance measure that aims to quantify perceptual difference between a vector of colours and a reference colour. The measure in question is the CIE Delta E (2000), which is calculated based on colour coordinates in Lab space. Colour contrast relates more specifically to legibility, in the context where text in one colour is overlaid on a background in another. The W3C definition used here ranges between 1 (identical colours, no contrast) and 21 (black on white, maximum contrast).

Usage

distance(shades, reference)

contrast(shades, reference)

Arguments

shades

One or more colours, in any suitable form (see shade()).

reference

A single reference colour.

Value

A numeric vector of distances or contrasts.

Author(s)

Jon Clayden code@clayden.org

References

See http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CIE2000.html for CIE Delta E. The contrast measure is defined as part of the W3C Web Content Accessibility Guidelines, version 2.0, detailed at https://www.w3.org/TR/WCAG20/.

Examples

distance(c("red","green","blue"), "red")
contrast(c("red","green","blue"), "red")

shades documentation built on July 3, 2026, 1:07 a.m.