0

I want to know the dominant colors present in the image below. I know a algorithm in openCV named k-mean algorithm but one should know the k before hand so I want to know how to find that k and exact RGB value of colors that are dominant and not the mean of those.

Lets take a example :

Pay with your face

In above image : k is 2 how to find that out and also how to find out Exact RGB value of pink(used on left most side) and blue (used on right most side) used in this (not the mean of their shades)

NOTE : Images will contain specific number of colors say 5 or 6 or 7 or 2 just like pictures designed by professionals. If there is a gradient present I want the RGB value of the extreme and not the mean of those colors.

EDIT 1 : The pink on the left turns to blue on the right so basically I want to find out from which color to which color is a gradient going.

Shashank Singh
  • 647
  • 1
  • 5
  • 22
  • 1
    The *k*-means algorithm doesn't return the mean of the values, except as a side effect. It *clusters* the actual data in such a way as to minimize the differences between the cluster members and the mean of the cluster. You don't have to know *k* beforehand, except that it can't be less than the number of values you want to cluster. To get the extremes you take the lowest member of the lowest cluster or the highest member of the highest cluster. The real issue is what you mean by *low* and *high*. What makes one shade of pink "lower" than another? – BoarGules Apr 25 '18 at 11:20
  • 2
    I think it is too broad question for StackOverflow... but as a suggestion maybe you can try to do kmeans with some predefined colors as initial centers (hue from hsv colorspace probably is better)... the clusters with more than 1 pixel will be the colors you have, and the initial center of that cluster is your color.... then, it is something that you have to code and try if it works, this is just an idea for such a broad question :) – api55 Apr 25 '18 at 12:57
  • 2
    Maybe it would make more sense doing the processing in a different colour space, say HSV (since you seem to be primarily concerned about hue)... – Dan Mašek Apr 25 '18 at 13:10
  • I think you should use color histogram of the image to find all colors and their frequency. you can easily choose dominant colors from that – user8190410 Apr 25 '18 at 14:01
  • @BoarGules The `pink` on the left turns to `blue` on the right so basically I want to find out from which color to which color is a gradient going. – Shashank Singh Apr 25 '18 at 15:18
  • I can see that. What I can't see is how you are going to explain that to a clustering algorithm. – BoarGules Apr 25 '18 at 15:38
  • @BoarGules It doesn't have to be this algorithm, I need to achieve something like that using any algorithm. – Shashank Singh Apr 26 '18 at 04:14

0 Answers0