Ask Your Question
0

cvtColor output unexpected channel count

asked 2013-07-13 21:26:40 -0500

pistorinoj gravatar image

updated 2013-07-14 12:11:07 -0500

I am using OpenCV 2.4.6 on a Windows 8 64 bit machine using VS2012 c++/cli. I want to take a CV_8UC3 color image, convert it to grayscale and display it.

cvtColor is not outputting what I would expect. Based on the documentation, where OriginalMat is a CV_8UC3 image, both of the following should output a CV_8UC3 image:

cvtColor(OriginalMat,NewMat,CV_RGB2GRAY);
cvtColor(originalMat,NewMat,CV_RGB2GRAY,3);

Instead, both output a CV_8UC1 image.

Perhaps the documentation should be changed to reflect the fact that when working with grayscale, the output will always be single channel and any hard coded channel count will be ignored.

edit retag flag offensive close merge delete

Comments

try to find someone posts questions, you can get your answer.

wuling gravatar imagewuling ( 2013-07-14 10:12:56 -0500 )edit

why would you expect, that cvtColor(OriginalMat,NewMat,CV_RGB2GRAY); outputs a 3chan image ?

berak gravatar imageberak ( 2013-07-14 15:13:56 -0500 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2013-07-14 17:44:47 -0500

As I read the doc, this behavior is perfectly normal. A color image, convert to a grayscale image should have only one channel. The doc says the destination image is the same size and depth (ie 640x480 image in 8U -> gives 640x480 image in 8U but with one channel).

I'm a little bit surprise by the second version. I suppose this version is only used when their is some ambiguities... but I don't know when...

edit flag offensive delete link more

Comments

Sorry, that I am such a newbie that these things throw me. As a newbie, I would not expect the channel count to change and that did not jump out at me from the docs.

The docs say:"dstCn – number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code "

That does not make clear to the newbie crowd (or at least me) that the channel count may be different than the incoming image.

Also, the fact that a hard coded channel count will be ignored was not expected.

In any event, a suggestion to consider changing the docs in this regard. Thanks again.

pistorinoj gravatar imagepistorinoj ( 2013-07-14 21:00:37 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-07-13 21:26:40 -0500

Seen: 293 times

Last updated: Jul 14 '13