# How to incorporate white into color system?

P.S. An important update to answer 2.

In comparison to RGB, HSV is convenient because it keeps color in the separate channel. One problem. It does not include black and white. I don't need intensity of color(that is value), but humans do recognize black and white as separate colors.

White is absent.

edit retag close merge delete

Sort by ยป oldest newest most voted

Black and white are achromatic colors (https://en.wikipedia.org/wiki/Grey). In HSV model they are represented with S=0 and V=0 or V=100.

Check this interactive app: http://colorizer.org/

more

I agree. That is, for complete color detection we need to take into account all components, not only hue. I formulate the full algorithm in my variant of the answer.

( 2019-01-30 12:49:50 -0500 )edit

2 steps are required:

1. Split the image into 3 planes: h, s, v. Create the histogram of h-plane.

1. Filter out colored pixels that is those where s is greater than some threshold. This requires thresholding of colored, 3-channel images. Split the result and create a histogram again. This time of v-plane.

Peaks on the first histogram are used to detect main colors. Peaks on the second - for black, gray, and white. You may be satisfied by gray only or subdivide it further: dark gray, gray, light gray ... There are 3 colors on this picture: white, black, and brown.

P.S.

Matters turn much more complicated. This algorithm works incorrectly because the black may be colored. A better version:

1. Choose some threshold of saturation and use it to split the image into two. The first will contain only gray pixels, the second - only colors.

2. Choose some threshold of v(alue). Everything below it from both sources will be black. Use those pixels as needed, then filter out. Don't fill them with Scalar(0,0,0). This will create problems in histogram calculation because this is a meaningful black pixel. Mark them in mask array and supply it for calcHist() later.

3. Split both remaining images into 3 planes: h1, s1, v1 and h2, s2, v2.

4. Create the histogram of h2-plane and use its peaks to detect main colors.

5. Create the histogram of v1-plane and use its peaks to detect gray and white.

This may seem boring, but you will be rewarded by results. The previous histogram was smoothed. This is not.

Histograms become less noisy, peaks - smooth, distinct, and sharp. Enjoy.

more

Official site

GitHub

Wiki

Documentation