Ask Your Question
1

How can a single channel represent a color image?

asked 2017-08-14 15:15:21 -0600

infoclogged gravatar image

updated 2017-08-14 15:41:12 -0600

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;
A = cv::imread("../data/image.png", CV_8UC3);
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 flag offensive close merge delete

Comments

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

Janko gravatar imageJanko ( 2017-08-14 15:41:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-08-14 17:57:59 -0600

Tetragramm gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-08-14 15:15:21 -0600

Seen: 1,338 times

Last updated: Aug 14 '17