3
votes

I have the code for computing the histogram for hsv and yuv images. As am trying to obtain values corresponding to brightness alone, I want the 'v' channel value from hsv image and luma ('y') channel value from yuv image. this is the code I have used.

    int channels[] = {0};
    calcHist(&src_yuv,1,channels,Mat(),hist,1,histSize,ranges,true,false);

This sample code is for yuv. I just change {0} to {2} to obtain 'v' channel values from HSV. I am getting certain results, but am not sure if am choosing the right channels. could you please help me, to know if those numbers choose the exact channels I want to? Thanks in advance

1
forgive my nescience. I read through that and developed my code according to that. But I was not confident if by just naming the channel as {2} would get the 'v' channel for me. The doc says it will get channel 0 and 1, but it wasn't specific if it gets the hue and saturation, by meaning {0,1}. Please forgive me if the question is pretty rudimentary.Lakshmi Narayanan
It is actually problematic to do that in OpenCV, since it doesn't guarantee that such information is stored. Basically, you have to manage to track it yourself.mmgp

1 Answers

2
votes

To be absolute sure that the channel number X corresponds to the channel you are after, consult the channelSeq attribute of the IPL Image structure. If channelSeq[X] gives the name (a character) of the channel you are after, then you found it.

But, given how this attribute is documented (along other interesting ones), even if you were always using IPLImage, there is no guarantee that the information contained there would be accurate. Thus, to be absolutely sure about the channel sequence in your image you have to trust the conversion specification and remember that yourself. So, if you start with an image in BGR and convert using BGR2YUV, then you trust that the Y channel is the first one, and so on. If OpenCV ever changes BGR2YUV to mean that Y goes to the last channel, and so on, then too bad for you.