Color Differences

The colordiff function gives an approximate value for the difference between two colors.

julia> colordiff(colorant"red", colorant"darkred")
23.754149863643036

julia> colordiff(colorant"red", colorant"blue")
52.88136782250768

julia> colordiff(HSV(0, 0.75, 0.5), HSL(0, 0.75, 0.5))
19.485910662571335
    colordiff(a::Color, b::Color; metric=DE_2000())

Evaluate the CIEDE2000 color difference formula by default. This gives an approximate measure of the perceptual difference between two colors to a typical viewer. A larger number is returned for increasingly distinguishable colors.

Options for metric are as follows:

MetricSummary
DE_2000The color difference using the recommended CIE Delta E 2000 equation.
DE_94The color difference using the recommended CIE Delta E 94 equation.
DE_JPC79McDonald's "JP Coates Thread Company" color difference formula.
DE_CMCThe color difference using the CMC l:c equation.
DE_BFDThe color difference using the BFD equation.
DE_ABThe original ΔE*, Euclidean color difference equation in the Lab colorspace.
DE_DIN99The Euclidean color difference equation applied in the DIN99 colorspace.
DE_DIN99dThe Euclidean color difference equation applied in the DIN99d colorspace.
DE_DIN99oThe Euclidean color difference equation applied in the DIN99o colorspace.

The following charts show the differences between the three colors for each metric with the default parameters:

The difference in the size of circles in the charts above represents the difference in the scale. The radii of the circles are all 20 in their scale units, so larger circles mean that the metric returns smaller values. Therefore, we should not compare the color differences between different metrics.

Colors.colordiffFunction
colordiff(a, b; metric=DE_2000())

Compute an approximate measure of the perceptual difference between colors a and b. Optionally, a metric may be supplied, chosen among DE_2000 (the default), DE_94, DE_JPC79, DE_CMC, DE_BFD, DE_AB, DE_DIN99, DE_DIN99d and DE_DIN99o.

The return value is a non-negative number in a type depending on the colors and metric.

Note

The supported metrics measure the difference within Lab or its variant colorspaces. When the input colors are not in the colorspace internally used by the metric, the colors (e.g. in RGB) are converted with the default whitepoint CIE D65 (Colors.WP_D65). If you want to use another whitepoint, convert the colors into the colorspace used by metric (e.g. Lab for DE_2000) in advance.

Colors.DE_2000Method
DE_2000()
DE_2000(kl, kc, kh)

Construct a metric of the CIE Delta E 2000 recommendation, with weighting parameters kl, kc and kh as provided for in the recommendation. When not provided, these parameters default to 1.

Colors.DE_94Method
DE_94()
DE_94(kl, kc, kh)

Construct a metric of CIE Delta E 94 recommendation (1994), with weighting parameters kl, kc and kh as provided for in the recommendation. When not provided, these parameters default to 1. The DE_94 is more perceptually uniform than the DE_AB, but has some non-uniformities resolved by the DE_2000.

Colors.DE_JPC79Method
DE_JPC79()

Construct a metric using McDonald's "JP Coates Thread Company" color difference formula.

Colors.DE_CMCMethod
DE_CMC()
DE_CMC(kl, kc)

Construct a metric using the CMC equation (CMC l:c), with weighting parameters kl and kc. When not provided, these parameters default to 1.

Note

The DE_CMC is a quasimetric, i.e. violates symmetry. Therefore, colordiff(a, b, metric=DE_CMC()) may not equal to colordiff(b, a, metric=DE_CMC()).

Colors.DE_BFDMethod
DE_BFD()
DE_BFD([wp,] kl, kc)

Construct a metric using the BFD equation, with weighting parameters kl and kc. Additionally, a whitepoint wp can be specified, because the BFD equation must convert between XYZ and Lab during the computation. When not provided, kl and kc default to 1, and wp defaults to CIE D65 (Colors.WP_D65).

Colors.DE_ABMethod
DE_AB()

Construct a metric of the original CIE Delta E equation (ΔE*ab), or Euclidean color difference equation in the Lab (CIELAB) colorspace.

Colors.DE_DIN99Method
DE_DIN99()

Construct a metric using Euclidean color difference equation applied in the DIN99 colorspace.

Colors.DE_DIN99dMethod
DE_DIN99d()

Construct a metric using Euclidean color difference equation applied in the DIN99d colorspace.

Colors.DE_DIN99oMethod
DE_DIN99o()

Construct a metric using Euclidean color difference equation applied in the DIN99o colorspace.