This is a discussion on Find similar Colors within the C# Programming forums, part of the Software Development category; Find similar colors Hello, I am working on a project that needs me to calculate simlar colors that the user ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Find similar colors Hello, I am working on a project that needs me to calculate simlar colors that the user selects from a 'color wheel' type control. So if the user chooses a Red based color, I need to return all the products that are Red (the products RGB or HEX color will be stored in the database). My question is, is there a formula that would determin if 2 colors are related? Example: RGB: 236,19,233 and RGB:117,56,116 are both Purples, and if the second one was stored in the Database, a search by a user who selects the first one as the color, should return the one in the database. Now if the selected color was RGB: 230,9,9 (Red base), it would *not* be returned because its not similar. I have a feeling there is a formula where you can set a certain variance and it will 'score' the similarity, but I cant seem to find it. Any help would be greatly appreciated! Filed under: GDI+, Graphics, gd+ Thanks.. S.Balasubramanian.. |
| Sponsored Links |
| |||
| Hi, I hope this helps getting you in the right direction. Working in the RGB color space will be a bit difficult to achieve your objectives. You will first want to convert your selected and target colors to HSB since it what you are really after is matching the Hue of two colors regardless if they differ in Saturation or Brightness. Hues are measured from 0 to 360 degrees, and Saturaion and Brightness are measured from 0 to 100 percent. Since the interpretation of colors can be a bit subjective you will need to set your allowable Hue tolerance. To keep things simple lets consider the following colors in the HSB color space and assume you are only after Hue matches Offset = 20 degrees. GREEN (120,100,100) - Your Target Color. PURPLE(290, 70, 50) - Your Selected Color Calling the following method would return false. if (IsColorMatch(20, 120, 290)) // Get Color from Database else // Do something else private bool IsColorMatch(int offset, int targetHue, int selectedHue) { bool retVal = true; int maxTarget = targetHue + offset; int minTarget = targetHue - offset; if ((selectedHue < minTarget) || (selectedHue > maxTarget) retVal = false; return retVal; }
__________________ The OXYGEN Delivers edgy, intelligent Technology to all... |
| |||
| Hi, Ok that defintely helped! One thing that i have noticed is that black, white, and grey colors need to be 'handled' somehow because they can exist in pretty much any Hue. I was thinking to set a flag if the brightness/saturation was under a certain level to store a special value for white, black (-1 and -2 i was thinking). Do you have a better approach? I ended up setting those flags for white, grey and black by checking the Saturation and Brightness.. my search results are working exactly as expected. Thanks again! S.Balasubramanian.. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why so JavaScript and Java have similar name? | Sabari | HTML, CSS and Javascript Coding Techniques | 1 | 08-20-2007 11:44 PM |
| Why the colors on my page look different when viewed on a Mac and a PC? | oxygen | HTML, CSS and Javascript Coding Techniques | 1 | 07-27-2007 03:57 AM |
| How can I have two sets of links with different colors? | oxygen | HTML, CSS and Javascript Coding Techniques | 1 | 07-27-2007 03:43 AM |
| Why so JavaScript and Java have similar name? | Sabari | Java Programming | 4 | 07-17-2007 05:17 AM |
| Colors and fonts | sanray316 | Web Design Help | 4 | 03-25-2007 10:29 PM |