One easy-to-implement method: colour cube.

Define a colour using its RGB values as a 3-tuple (r, g, b) and standard 
colours (ri, gi, bi) (where i = 0..n).The square distance between the given 
colour and a standard colour is (ri-r)^2+(gi-g)^2+(bi-b)^2. You can calculate 
square distances between the given colour and each of the standard colours, and 
the one with the minimal squared distance is the best match.

Better methods may exist, consult a book on computer vision or fine arts maybe?

On Jun 17, 2014, at 18:52, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
wrote:

> Hi all,
> 
> Is there a way of identifying the closest match to a given NSColor, out of a 
> list of possible colors to match? The user could have selected any color 
> using the color picker, but I would like to know whether it is "approximately 
> red", green, blue or white.
> 
> Of course, it might be e.g. magenta, and not really map well onto one of 
> those four, but I would still be interested in knowing the best guess. It 
> struck me that there might be an API for that, but I couldn't immediately 
> find one.
> 
> I could probably come up with a way of doing this myself, but thought I'd see 
> if there was anything out there already.
> 
> Cheers
> Jonny.
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/xcvista%40me.com
> 
> This email sent to xcvi...@me.com

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to