Ask Your Question
1

How to incorporate white into color system?

asked 2019-01-28 12:21:01 -0600

updated 2019-02-14 07:00:27 -0600

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.

image description image description

White is absent.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
5

answered 2019-01-29 06:23:08 -0600

mshabunin gravatar image

updated 2019-01-29 06:23:48 -0600

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/

edit flag offensive delete link more

Comments

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.

ya_ocv_user gravatar imageya_ocv_user ( 2019-01-30 12:49:50 -0600 )edit
1

answered 2019-01-30 12:54:53 -0600

updated 2019-02-14 06:52:52 -0600

2 steps are required:

image description

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

image description

  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.

image description

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.

image description

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-01-28 12:21:01 -0600

Seen: 592 times

Last updated: Feb 14 '19