I have a predefined array of rgb values. I want to be able to compare a user defined color to my array and return the closest match in Objective C.
Any help is greatly appreciated.
You could try finding the Sum-of-Squared-Differences between your predefined color and the user defined color and choose the predefined color with the minimum "distance".
E.g. suppose the user-defined color is [120 300 200]
and a predefined color is [100 250 150]
, then the sum of squared differences and the score is:
(120-100)*(120-100) + (300-250)*(300-250) + (200-150)*(200-150) = 5400
- and choose the prefefined color with the least difference.
You need to decide in what colour space you are testing.
HSL is arguably a better colour space than RGB because you can give more weight to "hue difference" and less to "lightness". In RGB space you need to skew your differences because the eye is better at discerning shades of green than other colours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With