Color Detection Algorithm
I am trying to write an algorithm for detection of the color green. The thing is that if I try detecting the shade of a pixel in a picture, there are more than a million different shades possible. How do I sift thourgh all these different shades and detect which ones are green ? Does anyone know of a simple way to do it or of any prevelant algorithms that does it for you ?
Re: Color Detection Algorithm
I think you should give more tolerance to the brightness. To do so, norm the color vectors by 1 and then distance is distance between the resulting vectors+some cooff*difference in length.
Re: Color Detection Algorithm
Nice idea RoboTact. Though, that depends on what the seach is done for. Maybe the user doesn't want to give tolerance to brightness. But if he does, then you are right, that by normalizing the RGB coefficients he achieves that.
Another way to do this is to execute histogram equalisation in each coefficient (R,G,B), or even better to transform the RGB matrix to HSI and perform histogram equalisation to the I coefficient only.
Re: Color Detection Algorithm
Assuming you receive pixel values in RGB form, another option is to convert the color to HSV (Hue - Saturation - Value). Pure green has (I believe) a hue value of 192.
This would make it easier to weight saturation and light levels differently than hue.
--
Scott
Re: Color Detection Algorithm
with a screen that is 32 bit you use this (this is how I get colours from a direct draw surface)
long colour = (*(reinterpret_cast<long*>(ddsd.lpSurface)+(Y*Xres+X)))&0x00FF00
&0x00FF00 is a bit mask that will extract the green value so all you need to do is this
if(colour) //if true then there is some green in the pixel
there ya go :) be carefull with 16 bit numbers as some systems consider 16 bit to be 15 ;)
(ddsd.lpSurface is a void pointer to the beginning of the screens memory address, which is why it needs to be reinterpreted)
oh and in a 24bit BMP (just RGB no alpha) you have 16,777,216 different colours ;)
Re: Color Detection Algorithm
Quote:
Originally Posted by wsmmi6674
Assuming you receive pixel values in RGB form, another option is to convert the color to HSV (Hue - Saturation - Value). Pure green has (I believe) a hue value of 192.
This would make it easier to weight saturation and light levels differently than hue.
--
Scott
Also: hsv is sometimes better to use for color detection problems. For example, it is prooved that for human skin color detection, hsi (or hsv) model is much better, because it is closer to human color perception.
Re: Color Detection Algorithm
How does HSV work? I've never heard of it
Re: Color Detection Algorithm
Whereas RGB represents the Red, Green and Blue components of a color, HSV represents the Hue, Saturation, and Value (light- or dark-ness) components. Some feel it is a better match with the way humans think about color. You can covert RGB colors to HSV using the algorithm found here: http://www.cs.rit.edu/~ncs/color/t_convert.html
--
Scott
Re: Color Detection Algorithm
HSV and HSI are 2 very similar color models. HSV stands for:
- H (hue): Ranges from 0-360. In some cases it is normalized 0-100. Hue represents the COLOR type (e.g. blue, red etc).
- S (saturation): Ranges from 0-100. It represents the "purity" of the color: the higher saturation value is, the clearer the color is. If saturation is low, the color looks closer to gray.
- V (value): This is the brightness of the color, and it ranges from 0-100.
HSV model is sometimes represented as a cone. Try find a tutorial for explanation on this.
How to convert from RGB to HSV:
Suppose you have (R,G,B) values:
MAX = max(R,G,B)
MIN = min(R,G,B)
then:
H = ((G-B)/(MAX-MIN))*60 if MAX = R
(2+(B-R)/(MAX-MIN))*60 if MAX = G
(4+(R-G)/(MAX-MIN))*60 if MAX = B
S = (MAX-MIN)/MIN
V = MAX
Hope it helps,
Theodore :wave:
Re: Color Detection Algorithm
hello yiannakop
please i want the matlab code because i need it urgently and as fast as possible in my graduation project thnx a lot.
Re: Color Detection Algorithm
please i want the matlab code ,it's very urgent
my mail is kimohoss@hotmail.com
please iu want it as soon as possible
Re: Color Detection Algorithm
You realize this post is almost 2 years old. It's possible Theodore isn't reading this forum anymore.
Viggy