Discussion:
problem with bayer to BGR conversion
Chaitan
2013-05-14 11:22:39 UTC
Permalink
I am not able to convert the raw bayer (RGGB..) image (from the ccd sensor) to 8-bit BGR.

Using the following code:

cv::Mat bayer16BitMat(image.height, image.width, CV_16UC1, image.bp);
cv::Mat bayer8BitMat = bayer16BitMat.clone();
bayer8BitMat.convertTo(bayer8BitMat, CV_8UC1, 0.0625);
cv::Mat rgb8BitMat(image.height, image.width, CV_8UC3);
cv::cvtColor(bayer16BitMat, rgb8BitMat, CV_BayerRG2BGR);

after running this code, i am getting image like this --> http://groups.yahoo.com/group/OpenCV/photos/album/1312742517/pic/1793350267/view?picmode=&mode=tn&order=ordinal&start=1&count=20&dir=asc



------------------------------------

Change settings: http://www.yahoogroups.com/mygroups, select
Get Emails (get all posts)
Daily Digest (one summary email per day)
Read on the web (read posts on the web only)Or Unsubscribe by mailing OpenCV-***@yahoogroups.com
Bob Davies
2013-05-15 15:51:21 UTC
Permalink
Chaitan - I saw where you found that code:

http://stackoverflow.com/questions/10403841/convert-12-bit-bayer-image-to-8-bit-rgb-using-opencv

It appears you didn't copy it correctly. You create bayer8BitMat but then
use bayer16BitMat in the last statement. Here is a less cluttered version
of the code that should work for you:

Mat bayer16Bit(image.height, image.width, CV_16UC1, image.bp);
Mat bayer8Bit, rgb;
bayer16Bit.convertTo(bayer8Bit, CV_8UC1, 0.0625);
cvtColor(bayer8Bit, rgb, CV_BayerRG2BGR);

Whenever you see echoes of your image like you did, it is because you have
incorrectly set the number of channels. In this case, you were converting
a 16-bit per channel image to CV_8UC3.

Bob Davies
Post by Chaitan
**
I am not able to convert the raw bayer (RGGB..) image (from the ccd sensor) to 8-bit BGR.
cv::Mat bayer16BitMat(image.height, image.width, CV_16UC1, image.bp);
cv::Mat bayer8BitMat = bayer16BitMat.clone();
bayer8BitMat.convertTo(bayer8BitMat, CV_8UC1, 0.0625);
cv::Mat rgb8BitMat(image.height, image.width, CV_8UC3);
cv::cvtColor(bayer16BitMat, rgb8BitMat, CV_BayerRG2BGR);
after running this code, i am getting image like this -->
http://groups.yahoo.com/group/OpenCV/photos/album/1312742517/pic/1793350267/view?picmode=&mode=tn&order=ordinal&start=1&count=20&dir=asc
chaitan divgi
2013-05-16 17:53:36 UTC
Permalink
oh yes, exactly.. i figured it out after post this message.. well thank you
Bob

chaitan
Post by Bob Davies
**
http://stackoverflow.com/questions/10403841/convert-12-bit-bayer-image-to-8-bit-rgb-using-opencv
It appears you didn't copy it correctly. You create bayer8BitMat but then
use bayer16BitMat in the last statement. Here is a less cluttered version
Mat bayer16Bit(image.height, image.width, CV_16UC1, image.bp);
Mat bayer8Bit, rgb;
bayer16Bit.convertTo(bayer8Bit, CV_8UC1, 0.0625);
cvtColor(bayer8Bit, rgb, CV_BayerRG2BGR);
Whenever you see echoes of your image like you did, it is because you have
incorrectly set the number of channels. In this case, you were converting
a 16-bit per channel image to CV_8UC3.
Bob Davies
Post by Chaitan
**
I am not able to convert the raw bayer (RGGB..) image (from the ccd sensor) to 8-bit BGR.
cv::Mat bayer16BitMat(image.height, image.width, CV_16UC1, image.bp);
cv::Mat bayer8BitMat = bayer16BitMat.clone();
bayer8BitMat.convertTo(bayer8BitMat, CV_8UC1, 0.0625);
cv::Mat rgb8BitMat(image.height, image.width, CV_8UC3);
cv::cvtColor(bayer16BitMat, rgb8BitMat, CV_BayerRG2BGR);
after running this code, i am getting image like this -->
http://groups.yahoo.com/group/OpenCV/photos/album/1312742517/pic/1793350267/view?picmode=&mode=tn&order=ordinal&start=1&count=20&dir=asc
Chaitan
2013-05-16 17:55:09 UTC
Permalink
oh yes, exactly.. i figured it out after post this message.. well thank you Bob



------------------------------------

Change settings: http://www.yahoogroups.com/mygroups, select
Get Emails (get all posts)
Daily Digest (one summary email per day)
Read on the web (read posts on the web only)Or Unsubscribe by mailing OpenCV-***@yahoogroups.com
Loading...