See Wikipedia's article on Color Difference for the right leads.
Basically, you want to compute a distance metric in some multidimensional colorspace.
But RGB
is not "perceptually uniform", so your Euclidean RGB
distance metric suggested by Vadim will not match the human-perceived distance between colors. For a start, L*a*b*
is intended to be a perceptually uniform colorspace, and the deltaE metric is commonly used. But there are more refined colorspaces and more refined deltaE formulas that get closer to matching human perception.
You'll have to learn more about colorspaces and illuminants to do the conversions. But for a quick formula that is better than the Euclidean RGB
metric, just do this:
- Assume that your
RGB
values are in the sRGB
colorspace
- Find the
sRGB
to L*a*b*
conversion formulas
- Convert your
sRGB
colors to L*a*b*
- Compute deltaE between your two
L*a*b*
values
It's not computationally expensive, it's just some nonlinear formulas and some multiplications and additions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…