MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / rgbToLab

Function rgbToLab

web/js/algorithms.js:16–27  ·  view source on GitHub ↗
(r, g, b)

Source from the content-addressed store, hash-verified

14}
15
16function rgbToLab(r, g, b) {
17 const R = srgbToLinear(r), G = srgbToLinear(g), B = srgbToLinear(b);
18 let X = R * 0.4124564 + G * 0.3575761 + B * 0.1804375;
19 let Y = R * 0.2126729 + G * 0.7151522 + B * 0.0721750;
20 let Z = R * 0.0193339 + G * 0.1191920 + B * 0.9503041;
21 X /= 0.95047; Y /= 1.00000; Z /= 1.08883;
22 const f = v => v > 0.008856 ? Math.cbrt(v) : (7.787037 * v + 16 / 116);
23 const L = 116 * f(Y) - 16;
24 const a = 500 * (f(X) - f(Y));
25 const bv = 200 * (f(Y) - f(Z));
26 return [L, a, bv];
27}
28
29function labDistanceSq(lab1, lab2) {
30 return (lab1[0] - lab2[0]) ** 2 + (lab1[1] - lab2[1]) ** 2 + (lab1[2] - lab2[2]) ** 2;

Callers 3

buildLabPaletteFunction · 0.85
nearestLabColorFunction · 0.85
medianCutGetPaletteInLabFunction · 0.85

Calls 2

srgbToLinearFunction · 0.85
fFunction · 0.85

Tested by

no test coverage detected