Add function to find nearest color given an array of colors based on color difference using specified color spaces #512
Replies: 3 comments 2 replies
-
It's pretty easy to write one around the existing API, but I think it would get a lot of use if it was made part of the existing API, so I'm a +1 on this. |
Beta Was this translation helpful? Give feedback.
-
The function is defined as: Color.nearestColor(color, colorArray, colorSpace, weights)
Example code: const red = new Color("red");
const blue = new Color("blue");
const green = new Color("green");
const black = new Color("black");
Color.nearestColor("brown", [red, blue, green, black], "lab", [1, 1, 1]); |
Beta Was this translation helpful? Give feedback.
-
Why use a color space for color difference (especially given many are not perceptually uniform) and not a deltaE method which was designed for this? I’m not sure we need a method for this, but I would support having this a "recipe" in the docs that people could copy paste, or a plugin. It's basically: function (color, colorArray, {deltaEMethod} = {}) {
let minDeltaE = Infinity, ret;
for (let c of colorArray) {
let deltaE = deltaE(color, c, deltaEMethod);
if (deltaE < minDeltaE) {
minDeltaE = deltaE;
ret = c;
}
}
return ret;
} |
Beta Was this translation helpful? Give feedback.
-
I want to add a function that finds the nearest color from an array of colors that are based on color difference using specified color spaces.
Beta Was this translation helpful? Give feedback.
All reactions