Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color difference/similarity% between two values with JS

Tags:

People also ask

How do you find the difference between two colors?

In order to measure the difference between two colors, the difference is assigned to a distance within the color space. In an equidistant-method color space, the color difference ∆E can be determined from the distance between the color places: ΔE = √ (L*₁-L*₂)² + (a*₁-a*₂)² + (b*₁-b*₂)².

How do you compare two RGB values?

If you have two Color objects c1 and c2 , you can just compare each RGB value from c1 with that of c2 . int diffRed = Math. abs(c1. getRed() - c2.

How do you compare colors?

The most common method would be a visual color comparison by looking at two physical color samples side by side under a light source. Color is very relative, so you can compare colors in terms of the other color across dimensions such as hue, lightness and saturation (brightness).


I need to compute the difference between two hex color values so the output is a percentage value. The first thing I discarted was converting the hex value into decimal, as the first one will have much higher weight than the last.

The second option is to compute the difference between each of the RGB values and then add them all. However, the difference between 0, 0, 0 and 30, 30, 30 is much lower than the one between 0, 0, 0 and 90, 0, 0.

This question recommends using YUV, but I can't figure out how to use it to establish the difference.

Also, this other question has a nice formula to compute the difference and output a RGB value, but it's not quite there.