```
distance[i] = abs(array[i].h - color.h)
+ abs(array[i].s - color.s)
+ abs(array[i].v - color.v))
```

and pick the lowest.
Solved

Posted on 2011-10-05

Given an array of hsv values and one color in hsv, how would I find the closest match in the array?

8 Comments

```
distance[i] = abs(array[i].h - color.h)
+ abs(array[i].s - color.s)
+ abs(array[i].v - color.v))
```

and pick the lowest.
For example if a difference in v is twice as bad as a difference in s and s and h are the same, then you could do it with

```
distance[i] = abs(array[i].h - color.h)
+ abs(array[i].s - color.s)
+ 2*abs(array[i].v - color.v))
```

Or if you want to scale it to 0-1 (and assuming the max value of each value is 255) use this```
distance[i] = (.25*abs(array[i].h - color.h)
+ .25*abs(array[i].s - color.s)
+ .5*abs(array[i].v - color.v))/255
```

Thanks for all the responses so far

http://adsabs.harvard.edu/

You could use the formula here and assume they know what they are talking about:

http://www.ee.columbia.edu

By clicking you are agreeing to Experts Exchange's Terms of Use.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**7** Experts available now in Live!