Color naming by value

Discussion in 'iPhone/iPad Programming' started by Mvkoe, Feb 4, 2013.

  1. macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #1
    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
     
  2. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
  3. thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #3
    And then the question is, how is it possible that you can select a color, no matter what an gives the name ?
     
  4. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    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?
     
  5. thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #5
    That's not really a answer on my question lol
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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?
     
  7. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #7
    I was answering albertbarkley's, admittedly not quite on topic, question.
     
  8. thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #8
    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.
     
  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    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.
     
  10. thread starter macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #10
    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)
     
  11. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Well, I don't think there's an algorithm for this, so you'll probably need a lookup table of some kind.
     
  12. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #12
    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...
     
  13. xArtx, Feb 4, 2013
    Last edited: Feb 4, 2013

    macrumors 6502a

    Joined:
    Mar 30, 2012
    #13
    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.
     

Share This Page