HexToCol

0th

Percentile

Identify Closest Match to a Color Given by a Hexadecimal String

Given a color as a hex string #rrggbb, find the closest match in the table of known (named) colors.

Keywords
color
Usage
HexToCol(hexstr, method = "rgb", metric = "euclidean")
Arguments
hexstr
a color or a vector of colors specified as hexadecimal string of the form "#rrggbb" or "#rrggbbaa"
method
character string specifying the color space to be used. Can be "rgb" (default) or "hsv".
metric
character string specifying the metric to be used for calculating distances between the colors. Available options are "euclidean" (default) and "manhattan". Euclidean distances are root sum-of-squares of differences, and manhattan distances are the sum of absolute differences.
Details

Finds the color with the minimum squared distance in RGB space.

Value

The colorname(s) of the closest match(es) (if more than one).

See Also

ColToHex, ColToRgb, colors

Aliases
  • HexToCol
Examples
ColToHex(c("lightblue", "salmon"))

HexToCol(c("#ADD8E6", "#FA1572"))
HexToCol(Pal("Helsana"))

x <- ColToRgb("darkmagenta")
x[2,] <- x[2,] + 155
RgbToCol(x)
Documentation reproduced from package DescTools, version 0.99.19, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.