zeus
zeus

Reputation: 12975

how to detect the most similar color?

I have more than 2000 color names, and I want with a given color (ex: #0087b4) find in my list the color that is visually the most identic to this color. Is there any algorithm that can help me to do this?

Upvotes: 0

Views: 548

Answers (2)

dhanushka
dhanushka

Reputation: 10702

If you have a mapping from your color names to their color space values, you can use any nearest neighbor methods, like KNN or any fast-nearest-neighbor variants. If you want just one closest color, use KNN with k=1.

Another thing you can try is to stack all your colors in a matrix as rows and build a color matrix C, say, if you are using RGB color space, C will be a 2000x3 matrix, its nth row having the R, G and B components of your nth color. Then, to find the closest color to a color x, which is 3x1 vector having R, G and B components, compute the product, C.x, this should give you a 2000x1 vector, find the index of its largest element. Color corresponding to this row is the closest color to x. For better accuracy, you can normalize the colors in both C and x. Find the means and variances of R, G and B components of your colors in C and use these values to normalize colors in C and color x.

Upvotes: 1

Sreevathsabr
Sreevathsabr

Reputation: 689

I don't know how far this will help you! I had a similar kind of problem. When we talk above human visibility it all depends on perspectives, it differs from one person to another. The Red Which is Red to me, may or may not be red to me. So it very difficult to make a module that works for everyone. I found HSV format of the image will be the one that works well here.

As

H ---> Represents the change in color from band to another like Red, Green, Blue, Cyan, Magenta, Yellow

S ---> When we change the S, color will be moved in the same color band which is been selected in the H

V ----> When we change the V, we will see a change in the Brightness.

As per many study contrast of The human visual system is more sensitive to contrast than absolute luminance

So I think, Based on above you can Provide range of HSV value of the color which you need to detect and find them in that range

Upvotes: 1

Related Questions