Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
Hey

I was wondering, is it posible to give the color a name, when you got the hex value of the color.

So if you would have #FFFFFF it would say "White", some apps have this, are they having some sort of algoritme or an pre defined color table with the value's and names in it ?

Grz
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,553
6,053
I always wonder that how HEX of RGB is given. Suppose that we have HEX FF7F50 and RGB 255,127,80. My question is that how FF7F50 is calculated or driven from 255,127,80..!! Still i could not find my question from anywhere.

All you do to go from 255, 127, 80 to FF7F50 is replace each of the 3 components with hexadecimal and remove the spaces and/or punctuation between them. To go the other way, break up each pair of characters and then convert from hexadecimal to decimal. Is that the answer to your question?
 

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
All you do to go from 255, 127, 80 to FF7F50 is replace each of the 3 components with hexadecimal and remove the spaces and/or punctuation between them. To go the other way, break up each pair of characters and then convert from hexadecimal to decimal. Is that the answer to your question?

That's not really a answer on my question lol
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
And then the question is, how is it possible that you can select a color, no matter what an gives the name ?

So, you want a method where you pass it an RGB value in hex and it returns a name, in a string presumably? Note that many RGB values don't have a HTML color name equivalent and UIColor is even more restrictive. And what would you use this 'name' for?
 

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
So, you want a method where you pass it an RGB value in hex and it returns a name, in a string presumably? Note that many RGB values don't have a HTML color name equivalent and UIColor is even more restrictive. And what would you use this 'name' for?

So Yes on your Question. Insert RGB value's ore HSL/HSV, and getting the closest HTML color name equivalent of the UIColor.

And I will use this for myself and other's that are colorblind for choosing the "right" (It's never 100% acurate but it does it) colors.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
So Yes on your Question. Insert RGB value's ore HSL/HSV, and getting the closest HTML color name equivalent of the UIColor.

I don't really understand what you're saying here. Is this method returning HTML color names (of which there are 147) or UIColor names (of which there are only 15)?

And I will use this for myself and other's that are colorblind for choosing the "right" (It's never 100% acurate but it does it) colors.

If you are having the user pick a color choice, why would you be starting from hex values? Perhaps elaborate some more on why you need this and how your method will be used.
 

Mvkoe

macrumors regular
Original poster
Aug 4, 2008
103
3
Belgium
I don't really understand what you're saying here. Is this method returning HTML color names (of which there are 147) or UIColor names (of which there are only 15)?



If you are having the user pick a color choice, why would you be starting from hex values? Perhaps elaborate some more on why you need this and how your method will be used.

Oke so, I'll use this "app" for making my life easier, choosing colors right. Like i'm in a shop, getting a t-shirt and i want to know the color of it.

Take photo, select pixel of the t-shirt. en compare it to the closest HTML color name (http://www.w3schools.com/html/html_colornames.asp)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Well, I don't think there's an algorithm for this, so you'll probably need a lookup table of some kind.

I agree: you will have to have a lookup of values and an algorithm to decide which is "closest". I would note that the simplistic option of calculating absolute difference of the 3 components and adding them together then selecting the smallest difference may not result in the answer you would expect: visual difference of colours is a complex task and not an easy one to automate...
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
Some pixels from the camera are dud, and don't agree with the
pixels adjacent to it sometimes,
even if the whole scene is close to one colour.

You need to look at the value of five or so pixels and calculate
their mean average.

---

Put all of the hex values from the link you provided in a lookup table,
and all of their English names in another array in the same order.
Create an empty integer array with the same number of elements
as there are colours in the table.
Get the mean average of a few pixels from the camera, that's the input colour.

Calculate the total deviation of all three colour components of the first colour
value in the lookup table, and store the total deviation across all three colour
components in the first index of the integer array.
Do this for the entire colour table.
Find the integer array element with the lowest value.
The colour name in English that has the same index is the closest colour with
a name in English.

Bear in mind the end of the answer above. The solution is rough.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.