45#ifndef UFO_VISION_COLOR_DELTA_E_HPP
46#define UFO_VISION_COLOR_DELTA_E_HPP
49#include <ufo/utility/type_traits.hpp>
50#include <ufo/vision/color/concepts.hpp>
51#include <ufo/vision/color/convert.hpp>
52#include <ufo/vision/color/space.hpp>
53#include <ufo/vision/color/type_traits.hpp>
66enum class ColorDeltaE {
90 auto const c = convert<F>(color);
91 auto const s = convert<F>(sample);
94 float const dg = c.gray - s.gray;
97 float const dr = c.red - s.red;
98 float const dg = c.green - s.green;
99 float const db = c.blue - s.blue;
100 return dr * dr + dg * dg + db * db;
102 float const dl = c.lightness - s.lightness;
103 float const da = c.a - s.a;
104 float const db = c.b - s.b;
105 return dl * dl + da * da + db * db;
107 float const dl = c.lightness - s.lightness;
108 float const dc = c.chroma - s.chroma;
109 float const dh = c.hue - s.hue;
110 return dl * dl + dc * dc + dh * dh;
112 static_assert(dependent_false_v<C>,
"Unknown color model");
139 float const ab_scale = 2.0f)
141 auto const c = convert<FineLab>(color);
142 auto const s = convert<FineLab>(sample);
144 float const dl = c.lightness - s.lightness;
145 float const da = ab_scale * (c.a - s.a);
146 float const db = ab_scale * (c.b - s.b);
147 return dl * dl + da * da + db * db;
159[[nodiscard]]
constexpr float deltaEOk(C
const& color, C
const& sample,
160 float const ab_scale = 2.0f)
176 ColorDeltaE method = ColorDeltaE::EUCLIDEAN,
179 if (ColorDeltaE::OK == method || ColorSpace::Oklab2 == space) {
185 case ColorSpace::Rgb:
187 case ColorSpace::Oklab:
189 case ColorSpace::Oklch:
194 assert(
false &&
"Not implemented.");
208[[nodiscard]]
constexpr float deltaE(C
const& color, C
const& sample,
209 ColorDeltaE method = ColorDeltaE::EUCLIDEAN,
212 return std::sqrt(
deltaESquared(color, sample, method, space));
Grayscale colors (Gray<T, Flags>).
Oklab perceptual colors (Lab<T, Flags>).
OkLch cylindrical colors (Lch<T, Flags>).
Rgb-family colors (gamma-encoded or linear: Rgb or Lrgb).
constexpr float deltaE(C const &color, C const &sample, ColorDeltaE method=ColorDeltaE::EUCLIDEAN, ColorSpace space=ColorSpace::NATIVE)
Computes the distance between two colors using a specified method.
constexpr float deltaESquared(C const &color, C const &sample, ColorDeltaE method=ColorDeltaE::EUCLIDEAN, ColorSpace space=ColorSpace::NATIVE)
Computes the squared distance between two colors using a specified method.
constexpr float deltaEEuclidean(C const &color, C const &sample)
Computes the Euclidean distance between two colors.
ColorSpace
Selects the working color space for color operations.
constexpr float deltaEOk(C const &color, C const &sample, float const ab_scale=2.0f)
Computes the Ok delta E distance between two colors.
constexpr float deltaEOkSquared(C const &color, C const &sample, float const ab_scale=2.0f)
Computes the squared Ok delta E distance between two colors.
constexpr float deltaEEuclideanSquared(C const &color, C const &sample)
Computes the squared Euclidean distance between two colors.
All vision-related classes and functions.
Primary template - intentionally undefined.