High schooler
High schooler

Reputation: 1680

Get most common colours in an image using OpenCV

Hi I'm using Opencv and I want to find the n most common colors of an image using x sensitivity. How could I do this? Are there any opencv functions to do this?

Cheers!

*Note: this isn't homework, i'm just using opencv for fun!

Upvotes: 3

Views: 4653

Answers (2)

GilLevi
GilLevi

Reputation: 2137

I would transform the images to the HSV color space and then compute a histogram of the H values. Then, take the bins with the largest values.

Upvotes: 4

Bull
Bull

Reputation: 11941

I assume by "x sensitivity" you mean you want to quantise the image.

You can cv2.calcHist() to do that. Without quantisation the histogram will be big (256*256*256). The link to the documentation has an example how to use calcHist (in C++, not Python but it would be almost the same). Once you have the histogram, just search for the cells with the largest values.

Upvotes: 2

Related Questions