How to identify patterns in color?

2

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

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

I'm using the RGB values as a basis, but I'm not having good results. For example:

A tone of any red, then the larger the number of R in the RGB system the lighter the color is. But this varies greatly from color to color.

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

Thank you in advance!

    
asked by anonymous 16.10.2015 / 15:29

1 answer

5

You have to make a sum of all three colors. At a minimum, R + G + B to get the full brightness and determine if the color is clear.

As the red and blue colors are darker, a black-and-white transformation 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 (it has ready-made algorithms out there) but another quick way is

1) Find the lowest value between R, G and B; 2) Decrease this value of the three colors; 3) According to the remaining values greater than zero, determine the hue.

There 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 compound colors, like a blend with more red than green is an orange, etc.

    
16.10.2015 / 15:38