Ask Your Question

Thomas Gooijers's profile - activity

2020-07-18 06:11:10 -0600 received badge  Popular Question (source)
2016-11-28 07:55:51 -0600 received badge  Nice Answer (source)
2016-11-28 04:27:13 -0600 received badge  Teacher (source)
2016-11-28 02:49:41 -0600 received badge  Self-Learner (source)
2016-11-28 02:46:52 -0600 answered a question How to convert from BGR to BayerRG

Thanks for your response Balaji R

In case anyone is interested here is how I solved it:

Mat ConvertBGR2Bayer(Mat BGRImage)   {

  /*
  Assuming a Bayer filter that looks like this:

  # // 0  1  2  3  4  5
  /////////////////////
  0 // B  G  B  G  B  G
  1 // G  R  G  R  G  R
  2 // B  G  B  G  B  G
  3 // G  R  G  R  G  R
  4 // B  G  B  G  B  G
  5 // G  R  G  R  G  R

  */


  Mat BayerImage(BGRImage.rows, BGRImage.cols, CV_8UC1);

  int channel;

  for (int row = 0; row < BayerImage.rows; row++)
  {
    for (int col = 0; col < BayerImage.cols; col++)
    {
      if (row % 2 == 0)
      {
        //even columns and even rows = blue = channel:0
        //even columns and uneven rows = green = channel:1 
        channel = (col % 2 == 0) ? 0 : 1;
      }
      else
      {
        //uneven columns and even rows = green = channel:1
        //uneven columns and uneven rows = red = channel:2 
        channel = (col % 2 == 0) ? 1 : 2;
      }

      BayerImage.at<uchar>(row, col) = BGRImage.at<Vec3b>(row, col).val[channel];
    }
  }

  return BayerImage;
}
2016-11-23 11:15:23 -0600 asked a question How to convert from BGR to BayerRG

I am working with a camera with an integrated vision system. I would like to use openCV to generate test images and upload these test images to the camera to evaluate the performance of the system. I have already been able to generate some useful test images but the camera assumes the picture being uploaded is a BayerBG pattern.

I noticed cvtColor can convert a Bayer pattern to BGR but I would like to do the exact opposite. As far as I can tell from the documentation there is no way to convert from BGR to Bayer.

Is there an other easy way to do this?