All of my methods are failing me in various ways. different lighting can mess it all up too.
has anyone every trying to return a name given a rgb value? "red" "green" "blue" would be enough to satisfy my needs for today.
i have unsafe byte processing of images from my web cam.
I personally find it more natural to think of colors in terms of hue/saturation/brightness than RGB values, and I think that would work well for you in this case. Try this:
Assign color names to certain ranges of the spectrum, as you see fit. For example, maybe red is 0-39, orange is 40-79, etc. (those are arbitrary numbers - I have no idea if they fit on any kind of scale or not). Then calculate the hue from your RGB value (you can find a formula here, although there may be others). Once you know the hue, you know what range of the spectrum it's in, and you can give it a name.
Here is a simple name scheme using two qualifiers and a color name:
You can easily adapt it if you want the blues to be more differentiated etc..
You can try this code
If you have a list of known colors with names, you can see which of those known colors a given target color is 'closest' to, using a 'closeness' function along the lines of (F# code):
Whichever one of the known colors has the smallest diff to the target color you want to name, use that name.
Well, Red/Green/Blue are fairly easy to identify by inspection; what range of values do you need to support?
The problem is that unless you start with a named color, it is very hard to get back to one;
IsNamedColor
will return false even if you create an obvious color via FromArgb.If you only need the actual expected standard colors, you could enumerate the known colors via reflection?
You might also be able to use this approach as a source of known colors for a more sophisticated algorithm.