Is there a way to calculate the histogram of vector

I have a 3-channel image , and I tried to get the histograms of 3 channels . Then I found out what I need is to count how many times every colors shows , it means I have to see every pixel as a 3D vector .

Can CalcHist make it ?

why are you doing this ? what is the purpose ?

it will compute an intensity distribution per channel
(an 1d vector for a single channel, a 2d plane for 2 channels, and a 3d cube for 3)

probably not what you wanted

to count ocurrences of rgb triplets, id propose something else:

map<int,int> counter; // key:color, val:count
// loop over pixels:
    Vec3b pixel =<Vec3b >(y,x);
    // integer encoding:
    int color = pixel[0] << 16 + pixel [1] << 8  + pixel[2];
    if (counter.find(color) == counter.end())
         counter[color] = 0; // new color
         counter[color] ++;

now you got a count for each rgb pixel in the map, to retrieve the resp. rgb value from the int (map key), do:

Vec3b pixel( (color>>16)&0xff, (color>>8)&0xff, color&0xff );

To estimate if the main color of the image is close enough to a given one .

Thanks for your advise , it does match my purpose .

Hi @sd3326852

It seems to me your are looking for histogram comparison. Check out the tutorial.

May be you can work it out without histograms. You can define a test to check if a color is close enough to the given one. inRange() function can perform such test.

You can try this sample