# How can a single channel represent a color image?

I am a total newbie and am going through the tutorials. So, I randomly picked up a pic from my computer and printed the number of channels of the image.

cv::Mat A;
std::cout << A.channels();


The answer is 1. But, what utterly confuses me is that how can a colored image can just be represented with one channel. And if it is only 1 channel, how do I know which channel does it represent ( R, G or B ) ?

Maybe I am missing the basics and corresponding materials can be referred to?

edit retag close merge delete

Hi,

Just out of curiosity, did you try to change "A.channels" to lets say "R.channels" ? If the answer would be again 1, then it is how many of A, or R, or G, or B channels do your image have,,, It seems to me that you "asked" how many Alpha channels does your image have, since A may mean Alpha channel.

Digital image can include four channels, the RGB as you mentioned plus one Alpha channel (transparency).

I am just another newbie in OpenCV... Let me know

( 2017-08-14 15:41:56 -0500 )edit

Sort by » oldest newest most voted

Fun fact, CV_8UC3 == 16. The function cv::imread takes an optional second parameter which is a flag from the enum cv::imreadmodes. In that enum, 16 == IMREAD_REDUCED_GRAYSCALE_2, which has the comment

If set, always convert image to the single channel grayscale image and the image size reduced 1/2.

Try removing that second parameter and see if it works better.

more

Official site

GitHub

Wiki

Documentation