1 | initial version |
To count how many pixel has a given colour you have to look at HSV color whell and define an aceptable bias for your colors or use standard bias for primary, secondary or tertiary colors. For example how do you consider orange, and magenta, and...?
Remeber that because in OpenCV an HSV image is 3chan x8bit, the Hue value is divided by 2 to fit 360° in 1 byte.
In the HSV color whell with secondary colors
H = 0°...30° => RED
H = 30°..90° => Yellow
H = 90°..150° => Green
H = 150°..210° => Cyan
H = 210°..270° => Blue
H = 270°..330° => Magenta
H = 330°..360° => RED
If you want to use only primary color (RGB) the above table becomes:
H = 0°...60° => RED
H = 60°..180° => Green
H = 180°..300° => Blue
H = 300°..360° => RED
Dividing Hue by 2 you have corresponding value ready for OpenCV:
Red : 0<= H <30 and 150<= H <180
Green : 30<= H < 90
Blu : 90<= H < 150
this are values you are looking for if you accept to count magenta and orange as red, cool yellow as green and so on.
Tips to count red pixel you can count not red than subtract to total pixel count
RedCount = numPixel - (greenCount-BlueCount)
I hope this helps