-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
cvtcolor bayer RGB conversions incorrectl aliases for BGR #4857
Copy link
Copy link
Closed
Milestone
Description
Transferred from http://code.opencv.org/issues/3992
|| Jason Newton on 2014-11-01 14:19
|| Priority: Normal
|| Affected: 2.4.9 (latest release)
|| Category: imgproc, video
|| Tracker: Bug
|| Difficulty: Easy
|| PR:
|| Platform: Any / Any
cvtcolor bayer RGB conversions incorrectl aliases for BGR
If we look at the existing flags for debayering we see two variants, one BGR:
CV_BayerBG2BGR, CV_BayerGB2BGR, CV_BayerRG2BGR, CV_BayerGR2BGR
The other RGB:
CV_BayerBG2RGB, CV_BayerGB2RGB, CV_BayerRG2RGB, CV_BayerGR2RGB
However, you will notice that corresponding RGB/BGR variants have the same values and thus cvtColor incorrectly returns a BGR image when the user requests RGB. In addition to confusion from the unexpected and undesired behavior, the user now also has to run an additional cvtColor with BGR2RGB, which is unnecessary work for large images and real time processing.
History
Vadim Pisarevsky on 2014-11-14 14:11
Obviously, BayerBG2BGR == BayerRG2RGB, so it's normal that some values are equal. If you can provide the sample that reproduces the bug, please, reopen the ticket.
- Status changed from New to Cancelled
Jason Newton on 2015-01-01 10:34
Vadim Pisarevsky wrote:
> Obviously, BayerBG2BGR == BayerRG2RGB, so it's normal that some values are equal. If you can provide the sample that reproduces the bug, please, reopen the ticket.
Hi Vadim,
You are right and I didn't think of code-reuse for some of them and the names blurred together to my eyes. The part I would like to understand what's going with this example - I've encountered unexpected BGR byte ordered images over and over again attempting to work with RGB - being explicit where I can/should be in some spots - mainly highgui but occationally - I think here with cvtColor. I've had problems with it hooked up on libdc1394, and gigevision cameras input and normally am doing these things from C++ but I've had the same issues (of course) when using them similiarly in python.
I hope you don't mind me showing you the attached python program and a few of the images it outputs - it's performing to my expectations of what I consider a bug but maybe I've been misunderstanding something about opencv's channel byte orders on little endian machines. On the off chance you do not like python or don't want to satisfy this snippet's dependencies I've also attached the test image it generates and debayered supposedly RGB and BGR images (which are flipped in display of external programs) - inspection of the arrays confirms the channels are not what we intended to come out for this BayerRG (rggb) image with R=G=0, B = 255.
In [1]: ImgRGB[:, :, 0] #What? R should be 0
Out[1]:
array([[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
...,
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255]], dtype=uint8)
In [2]: ImgRGB[:, :, 1]
Out[2]:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [3]: ImgRGB[:, :, 2]
Out[3]:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [4]: ImgBGR[:, :, 0]
Out[4]:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [5]: ImgBGR[:, :, 1]
Out[5]:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [6]: ImgBGR[:, :, 2]
Out[6]:
array([[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
...,
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255]], dtype=uint8)
- Status changed from Cancelled to Open
Jason Newton on 2015-01-01 10:37
attaching python test file and outputs
- File test_debayer.py added
- File BayerImg.png added
- File ImgRGB.png added
- File ImgBGR.png added
Vadim Pisarevsky on 2015-04-27 15:17
- Category set to imgproc, video
Reactions are currently unavailable