Bayer filter, bayer demosaicing OpenCV C++

huangapple go评论160阅读模式
英文:

Bayer filter, bayer demosaicing OpenCV C++

问题

我在bayer解码(OpenCV C++)方面遇到了一些问题。
我需要将图像从Bayer马赛克格式转换为正常版本。

我尝试使用cv::cvtColorcv::COLOR_BayerGB2BGR,但输出图像看起来很“绿”,我不明白为什么。
我也尝试了一些方式来使用双线性插值的cv::demosaicing,但也没有帮助。
我知道输出图像应该比输入图像小两倍,因为我们需要从4个像素中获取一个,但我不知道如何正确实现它。

更新:Bayer filter, bayer demosaicing OpenCV C++

#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);
}
英文:

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:Bayer filter, bayer demosaicing OpenCV C++

#include &lt;opencv2/opencv.hpp&gt;

int main()
{
    cv::Mat bayer_img = cv::imread(&quot;bayer_image2.png&quot;, 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(&quot;bayer_image_output.png&quot;, resized_img);
}

答案1

得分: 1

在你的代码中,你正在使用cv::COLOR_BayerGBRG2BGR进行转换,这可能与你的输入图像的实际Bayer模式不匹配。你看到的绿色输出可能是使用不正确的转换引起的。
要解决这个问题,你需要确定你的输入图像的正确Bayer模式,并使用适当的转换代码。最常见的Bayer模式有BayerBG、BayerGB、BayerRG和BayerGR。你应该根据你的摄像机传感器或图像来源选择正确的模式。

英文:

In your code, you are using cv::COLOR_BayerGBRG2BGR for the conversion, which may not match the actual Bayer pattern of your input image.
The greenish output you are seeing could be a result of using the incorrect conversion.
To solve this problem, you need to determine the correct Bayer pattern of your input image and use the appropriate conversion code. The most common Bayer patterns are BayerBG, BayerGB, BayerRG, and BayerGR. You should choose the correct pattern based on your camera sensor or image source.

答案2

得分: 0

Debayered pictures still need to be white-balanced. The raw sensor values aren't balanced.

There are various methods. You can

  • determine the balance manually (e.g. take the mean of each color plane) and then scale each color channel accordingly
  • apply histogram equalization to each color plane
  • anything more complex, to be found via research
英文:

Debayered pictures still need to be white-balanced. The raw sensor values aren't balanced.

There are various methods. You can

  • determine the balance manually (e.g. take the mean of each color plane) and then scale each color channel accordingly
  • apply histogram equalization to each color plane
  • anything more complex, to be found via research

huangapple
  • 本文由 发表于 2023年6月5日 01:21:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401584.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定