0

Can K-Means be used to find colour clusters? My objective is to find the most common colours (HSV colour space) that occur in an image.

Can I give the function kmeans() a comparison function to determine 2 colours distance between each other? Ie;

int sameColour(const Vec3b& color1, const Vec3b& color2)
{
    return (abs(color1[0] - color2[0]) +
        abs(color1[1] - color2[1]) +
        abs(color1[2] - color2[2])) < 30;
}

This way I get the 'general' colour clusters in an image.

sazr
  • 24,984
  • 66
  • 194
  • 362
  • One question--why do you have the `<30` if tbe function is meant to return an `int`? – eigenchris Aug 29 '16 at 15:00
  • Possible duplicate of [Is there a formula to determine overall color given BGR values? (OpenCV and C++)](http://stackoverflow.com/questions/34734379/is-there-a-formula-to-determine-overall-color-given-bgr-values-opencv-and-c) – Miki Aug 29 '16 at 15:10
  • You can also have a look at [this](http://stackoverflow.com/a/35482205/5008845) – Miki Aug 29 '16 at 15:12
  • most common colors can be found by histograms. but yes: color clusters can be computed by k-means, but with hsv it is a bit tricky, since the hue space is circular. – Micka Aug 29 '16 at 17:47

0 Answers0