aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
Distance.cppm File Reference

Partition aest.colors:distance: distance metrics between colors, Euclidean and the CIE color difference formulas. More...

#include <cmath>
#include <concepts>
#include <cstdint>
import aest.colors:space;

Go to the source code of this file.

Classes

struct  aest::colors::Euclidean< BasicRGB< Gamut, Transfer > >
 Euclidean distance in an RGB space: between the encoded values of encoded spaces, between the light of linear ones. More...
struct  aest::colors::Euclidean< OKLab >
 Euclidean distance in OKLab: ΔE_OK, the color difference of CSS Color 4, where equal distances look about equally different. More...
struct  aest::colors::Euclidean< CIELab >
 Euclidean distance in CIELab: ΔE*ab, the CIE 1976 color difference that de_76() measures. More...

Concepts

concept  aest::colors::EuclideanSpace
 A color space in which euclidean() can measure distances through Euclidean.

Enumerations

enum class  aest::colors::CIE94Application : std::uint8_t { graphic_arts , textiles }
 The application whose weights de_94() uses, as CIE 116-1995 defines them. More...

Functions

template<ColorType Space>
float aest::colors::channel_distance (const Space &color1, const Space &color2)
 Euclidean distance between the three channels of two colors, ignoring alpha.
template<EuclideanSpace Space = OKLab, ColorType Color1, ColorType Color2>
requires ConvertibleTo<Space, Color1> && ConvertibleTo<Space, Color2>
float aest::colors::euclidean (const Color1 &color1, const Color2 &color2, In< Space > space={})
 Euclidean distance between two colors.
template<ColorType Color1, ColorType Color2>
requires ConvertibleTo<CIELab, Color1> && ConvertibleTo<CIELab, Color2>
float aest::colors::de_76 (const Color1 &color1, const Color2 &color2)
 The CIE 1976 color difference ΔE*ab: the Euclidean distance in CIELab.
template<ColorType Color1, ColorType Color2>
requires ConvertibleTo<CIELab, Color1> && ConvertibleTo<CIELab, Color2>
float aest::colors::de_94 (const Color1 &reference, const Color2 &sample, const CIE94Application application=CIE94Application::graphic_arts)
 The CIE 1994 color difference ΔE*94.
double aest::colors::ciede2000_hue (const double a, const double b)
 Hue angle of a CIEDE2000 a', b' pair.
double aest::colors::ciede2000_chroma_weight (const double chroma)
 The CIEDE2000 chroma weight sqrt(C^7 / (C^7 + 25^7)).
template<ColorType Color1, ColorType Color2>
requires ConvertibleTo<CIELab, Color1> && ConvertibleTo<CIELab, Color2>
float aest::colors::de_2000 (const Color1 &color1, const Color2 &color2)
 The CIEDE2000 color difference ΔE00, the current CIE formula.

Detailed Description

Partition aest.colors:distance: distance metrics between colors, Euclidean and the CIE color difference formulas.

Author
Davide Pierotti

Definition in file Distance.cppm.

Enumeration Type Documentation

◆ CIE94Application

enum class aest::colors::CIE94Application : std::uint8_t
exportstrong

The application whose weights de_94() uses, as CIE 116-1995 defines them.

Enumerator
graphic_arts 

kL = 1, K1 = 0.045, K2 = 0.015: images, prints and screens.

textiles 

kL = 2, K1 = 0.048, K2 = 0.014: lightness counts half as much.

Definition at line 178 of file Distance.cppm.

Function Documentation

◆ channel_distance()

template<ColorType Space>
float aest::colors::channel_distance ( const Space & color1,
const Space & color2 )

Euclidean distance between the three channels of two colors, ignoring alpha.

Template Parameters
SpaceA color space whose channels form Cartesian coordinates
Parameters
[in]color1First color
[in]color2Second color
Returns
The distance between the channels.

Definition at line 33 of file Distance.cppm.

◆ ciede2000_chroma_weight()

double aest::colors::ciede2000_chroma_weight ( const double chroma)

The CIEDE2000 chroma weight sqrt(C^7 / (C^7 + 25^7)).

Parameters
[in]chromaA mean chroma
Returns
The weight in the 0-1 range, near 1 for saturated colors.

Definition at line 250 of file Distance.cppm.

◆ ciede2000_hue()

double aest::colors::ciede2000_hue ( const double a,
const double b )

Hue angle of a CIEDE2000 a', b' pair.

Parameters
[in]aThe a' channel, a* rescaled by CIEDE2000
[in]bThe b* channel
Returns
The hue in degrees, in the [0, 360) range; 0 when both are 0.

Definition at line 237 of file Distance.cppm.

◆ de_2000()

template<ColorType Color1, ColorType Color2>
requires ConvertibleTo<CIELab, Color1> && ConvertibleTo<CIELab, Color2>
float aest::colors::de_2000 ( const Color1 & color1,
const Color2 & color2 )
export

The CIEDE2000 color difference ΔE00, the current CIE formula.

It refines de_94() to follow the eye more closely: it rescales a* so that grays are judged evenly, weights lightness by its distance from the mid-gray, weights hue by the hue itself, and rotates the chroma and hue differences against each other around blue, where CIELab is least even. Unlike de_94(), it is symmetric. The parametric factors kL, kC and kH are all 1, the CIE reference conditions. This follows CIE 142-2001, with the hue rules that Sharma, Wu and Dalal (2005) made exact.

Template Parameters
Color1Color type of color1
Color2Color type of color2
Parameters
[in]color1First color
[in]color2Second color
Returns
The difference, ignoring alpha: 0 or greater, 100 from black to white, about 1 just noticeable.

Definition at line 279 of file Distance.cppm.

◆ de_76()

template<ColorType Color1, ColorType Color2>
requires ConvertibleTo<CIELab, Color1> && ConvertibleTo<CIELab, Color2>
float aest::colors::de_76 ( const Color1 & color1,
const Color2 & color2 )
export

The CIE 1976 color difference ΔE*ab: the Euclidean distance in CIELab.

The first CIE formula and the simplest: it overstates differences between saturated colors, which de_94() and de_2000() correct. It is euclidean<CIELab>(color1, color2).

Template Parameters
Color1Color type of color1
Color2Color type of color2
Parameters
[in]color1First color
[in]color2Second color
Returns
The difference, ignoring alpha: 0 or greater, 100 from black to white, about 2.3 just noticeable.

Definition at line 169 of file Distance.cppm.

◆ de_94()

template<ColorType Color1, ColorType Color2>
requires ConvertibleTo<CIELab, Color1> && ConvertibleTo<CIELab, Color2>
float aest::colors::de_94 ( const Color1 & reference,
const Color2 & sample,
const CIE94Application application = CIE94Application::graphic_arts )
export

The CIE 1994 color difference ΔE*94.

It weights the differences in lightness, chroma and hue of CIELCH: the chroma and hue differences count less as the chroma of reference grows, where the eye tells them apart less. The weights depend on reference alone, so the formula is not symmetric: swapping the colors gives another result unless their chromas are equal.

Template Parameters
Color1Color type of reference
Color2Color type of sample
Parameters
[in]referenceThe reference color, whose chroma sets the weights
[in]sampleThe color compared to reference
[in]applicationThe weights to use, those for graphic arts by default
Returns
The difference, ignoring alpha: 0 or greater, about 1 just noticeable.

Definition at line 202 of file Distance.cppm.

◆ euclidean()

template<EuclideanSpace Space = OKLab, ColorType Color1, ColorType Color2>
requires ConvertibleTo<Space, Color1> && ConvertibleTo<Space, Color2>
float aest::colors::euclidean ( const Color1 & color1,
const Color2 & color2,
In< Space > space = {} )
export

Euclidean distance between two colors.

Both colors are converted to Space and the distance between their channels is measured there, ignoring alpha. The default, OKLab, gives ΔE_OK, where equal distances look about equally different; euclidean<SRGB>(color1, color2) measures the encoded values, and euclidean<LinSRGB>(color1, color2) the difference in light.

Template Parameters
SpaceThe color space the distance is measured in
Color1Color type of color1
Color2Color type of color2
Parameters
[in]color1First color
[in]color2Second color
[in]spaceThe working space, e.g. in<LinSRGB>; OKLab when omitted
Returns
The distance: 1 from black to white in OKLab, and in the 0-sqrt(3) range for SRGB and for LinSRGB colors without HDR values.

Definition at line 147 of file Distance.cppm.