Get histogram of RGB image combined or how to store Vec3b in a map?
I have an image in which I require to get the distribution of colors on an RGB (BGR) basis as I need to locate the most dominant composite BGR color (like (255,126,34) occurred 45 times).
My naive approach was first to create a std::map<cv::vec3b,int> and loop over the image and put the colors into the map. However I was not able to write sth like
++myMap[vec];
as I am getting a compiler error telling me that there is no operator<
defined for Vec3b
. Obviously there is no defined operator for that.
Then I googled around and realized that the build-in histogram functions may solve the problem probably better. What I don't understand is how I should approach that as calcHist creates a channel separated histogram which I actually do not want. The local maximum of channel r on position n
must not necessary be the local maximum for channel g and b for the same n
which forces me to run some manual correlation of these values.
Is there a proper way of getting a hint of the distribution of composite RGB (BRG) pixels in a cv::Mat