0

I get a Bayer image(raw data) from the Basler camera and save it in a CSV file. again I get a GBR image from the camera and convert it to raw data using the code below and save it to a CSV file. but these two CSV files are different. 70 percent of the cells are exactly the same and others have the difference between -130 up to 127 but just 4 percent of them have a difference greater than 5 or less than -5. what is the problem? and how can I fix it? or is it normal?

cv::Mat ConvertBGR2Bayer(cv::Mat BGRImage)   {

  cv::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<cv::Vec3b>(row, col).val[channel];
    }
  }

  return BayerImage;
}

'''

forouzanf
  • 15
  • 3
  • Are you saying that two images obtained from a camera are not identical? Why is this surprising? What are you doing to avoid differences in what the camera sees? What are you doing to avoid noise? – Cris Luengo Aug 01 '21 at 13:44
  • Your comments don't match your code, which tells me that both are wrong. Your `even columns and even rows` and `even columns and uneven rows` comments both fall under the code that deals with only even rows, not with even columns. – JohnFilleau Aug 01 '21 at 13:44
  • @Cris Luengo the camera and the object and everything else is fixed so I guess two pictures shouldn't have difference although I think the light might have an effect and cause noise – forouzanf Aug 01 '21 at 14:07
  • Take two images and subtract them. Then you can tell if the differences are structural (a change in illumination perhaps?) or random (noise). Note that there is always noise, though you can probably make it so that it cannot be observed in the 8-bit output by having lots of light and a wide aperture. – Cris Luengo Aug 01 '21 at 14:11

0 Answers0