How to identify patterns in colors?

Asked

Viewed 480 times

2

I have an image and loop through each pixel of it.

I need to identify if the pixel color:
- It is a light or dark color;
- And the hue of it (for example if it is bluish or reddish, greenish, etc...).

I’m using the RGB values as a basis but I haven’t been getting good results. For example:

Any shade of red, the higher the R number in the RGB system the lighter the color is. But this varies a lot from color to color.

if (Color.DarkRed.R > 160) { // É um tom claro.}

Thank you in advance!

1 answer

5


You have to do a sum of the three colors. At least, R+G+B to get the full brightness and determine if the color is light.

As the colors red and blue are darker, a transformation to black-and-white that gives a better sense of brightness, is 0.21 R + 0.72 G + 0.07 B.

As for tonality, I would personally convert the RGB value to HSV (there are algorithms out there) but another quick way is

1) find the lowest value between R, G and B; 2) Decrease this value from the three colours; 3) According to the remaining values greater than zero, determine the shade.

Then you would have to implement a degree of tolerance for very weak colors, for example skin tone is that color? Red? Orange? Brown? Another challenge is to deal with composite colors, like a blend with more red than green is an orange tone, etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.