IT Community - Software Programming, Web Development and Technical Support

Find similar Colors

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-19-2007, 09:34 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Find similar Colors

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-19-2007, 09:37 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Find similar Colors

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-19-2007, 09:40 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Find similar Colors

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 11:02 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0