CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Color Shade by Color Proximity

    Good evening (at least to me),

    I'm not a very well English speaker, but I will try towards to resolve my problem.

    I would like some guidelines about how to categorize a RGB color by its proximity, or as I'd read, Color Shade.

    Example:

    The color #AAFFAA (170,255,170) is, visually, a derivation of pure green (0,255,0).

    But how can I do this distinction programatically?

    Of course, this is a very easy color, because is, let's say, full of green.

    But what if the given color is, for example, #D27A4B (210, 122, 75) - looks like a clay-brown.

    The main pure colors are: Red, Green, Blue, how the color above can be classified?

    Should I a keep a very refined list of colors, with specific tones of each color and compare by proximity? Or is there something better?

    All this is for mapping a terrain image. I'm creating a web game which each player will have a random "feud" (or something like that).

    I would like to have a lot of terrains images and assign randomly to each player.

    But one of tasks doable by players is Building Constructions and would like to restrict WHERE some buildings can be built.

    Example: A Mill can only be constructed over part of terrain specified as"grass", of some kind of plantation. But cannot be built over sidewalk, bridges, mountains...

    I've already created the image splitter and I can distinguish the most predominant color of the image, or each "tile", but if I can't classify it programatically, I can't continue.

    I tried this formula but I don't know the threshold values.

    I found some values here and here, but I think I didn't understood correctly how can I apply this concept to match and posteriorly classify the predominant color of image.

    Thanks for helping

  2. #2
    Join Date
    Sep 2010
    Posts
    5

    Re: Color Shade by Color Proximity

    Why do you need to determine dynamically where can be constructed? I'd say it's much easier to determine this in advance per background, or maybe even better, use tiles that are randomly combined.

    If not, I'd convert the color to HSB (Hue, Saturation, Brightness). You can determine hue intervals to distinguish the "color", then with further intervals you can restrict the brightness and saturation in order to exclude shades of gray, etcetera. Does this help you?

  3. #3
    Join Date
    Sep 2010
    Posts
    3

    Re: Color Shade by Color Proximity

    It's almost exactly what I'm trying to do with tiles, but instead of creating an image by randomizing its position, I'm coding in other way, by splitting an external image into N tiles.

    About the Color Space, I was reading (a lot, during 2 weeks) that the best space is HSI (Hue, Saturation, Intensity), because it's closer than human eye vision.

    But I can't convert RGB to HSI (and, HSI to RGB) because I can't find a readable algorithm (or understandable in my coding language) or even understand the formulae.

    I found a very good formulae, but what in h*ell means cos raised to -1 ?

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Color Shade by Color Proximity

    Quote Originally Posted by Bruno Augusto View Post
    But I can't convert RGB to HSI (and, HSI to RGB) because I can't find a readable algorithm (or understandable in my coding language) or even understand the formulae.
    Hmmm... I've done that conversion a long time ago in PostScript, but I doubt that code would be a big help to you, even if I'd still have it. Unfortunately, I can't give you the formulae off-hand either.

    I found a very good formulae, but what in h*ell means cos raised to -1 ?
    It is a common alternative way to write arc cos. (It was written that way on the keyboard of HP calculators for instance, if I recall it correctly.) But it may also mean 1/cos. I think it should be possible to determine from the context which one is meant, provided some math background.

  5. #5
    Join Date
    Sep 2010
    Posts
    3

    Re: Color Shade by Color Proximity

    Well, I appreciate the explanation about arc cos, but in this meanwhile I figured out by myself, from another version of this formulae, written in Delphi I think.

    I'm trying to adapt this algorithm (PDF) I've found searching a lot.

    But even if I do the math correctly, I can't match my results with this file examples.

    In file is shown 1.167π, but if I multiply the whole math by 2π I get different results.

    Perhaps somebody good in Maths / Geometry can me explain how this formula should be built, so I think I can do it by myself.

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Color Shade by Color Proximity

    Quote Originally Posted by Bruno Augusto View Post
    In file is shown 1.167π, but if I multiply the whole math by 2π I get different results.
    I'm not quite sure what you're referring to, but I think it's step two of the example conversion on page 2 of that PDF file, because that's the only place where I see a 1.167π in there.

    If I repeat the calculation, I get exactly the result that's shown there. Are you sure you set your calculator to radians rather than degrees? And, BTW, I don't see anything there that says you should multiply whatever with 2π.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured