I have some troubles with bayer-demosaicing (OpenCV C++). I need to convert the image from the Bayer mosaic to the normal version.
I tried to use the cv::cvtColor
with cv::COLOR_BayerGB2BGR
, but the output image looks so "green" , and I don't understand why.
I also tryed to somehow use cv::demosaicing
for bilinear interpolation, but that didn't help either.
I know that the output image should be two times smaller than the input one, because we have to get 1 out of 4 pixels, but I don't understand how to implement it correctly.
Upd:
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat bayer_img = cv::imread("bayer_image2.png", cv::IMREAD_GRAYSCALE);
cv::Mat rgb_img;
cv::cvtColor(bayer_img, rgb_img, cv::COLOR_BayerGBRG2BGR);
cv::Mat demosaiced_img;
cv::cvtColor(rgb_img, demosaiced_img, cv::COLOR_BGR2RGB);
cv::Mat resized_img;
cv::resize(demosaiced_img, resized_img, cv::Size(), 0.5, 0.5);
cv::imwrite("bayer_image_output.png", resized_img);
}