0

I have a bunch of values that seem to be 12-bit numbers. If I put them in a matrix and scale each one to a value 0-255 and then show them as an image, I get something that looks like a photo, but it's quite bland.

I think that they might be direct reading off of a camera sensor. They have a sort of stippled pattern, kind of like plaid, that makes me think that they might be a sort of Bayer filter. https://en.wikipedia.org/wiki/Bayer_filter

I want to convert these number into RGB values. What do I need to do? For each 2x2 in the Bayer pattern, do I convert the red to R, blue to B, and then average the green values? Do I need a gamma correction?

I noticed that the max value is much lower than the full 0xfff. Do I need to scale the values?

Eyal
  • 5,728
  • 7
  • 43
  • 70
  • In case it is Bayer CFA, you may use OpenCV `cvtColor` method with one of the 4 options: `COLOR_BayerBG2BGR`, `COLOR_BayerGB2BGR`, `COLOR_BayerRG2BGR`, `COLOR_BayerGR2BGR`. In case it's a raw image, you may have to apply white balance, gamma, and contrast enhancement. It's hard to answer without the raw data file. Can you please share it? – Rotem Apr 12 '22 at 19:25
  • I'm unable to share it because it is proprietary, sorry. Are those four options the four different Bayer filter patterns? I have tried all four patterns and none of them were perfect. – Eyal Apr 19 '22 at 20:18
  • Yes, Bayer pattern has only 4 options (out of 2x2 pixels 2 pixels are green in the diagonal, one is red and one is blue). There are many other CFA options, but Bayer is the most common. – Rotem Apr 19 '22 at 20:52

1 Answers1

0

The procedure is well-described here: https://www.strollswithmydog.com/raw-file-conversion-steps/

Looks like I was getting it mostly right by the problem was grey balance. There is a transformation that needs to be made on the sensor values to map it to the 0-255 RGB component and the transform that needs to be made depends on the color. The best way is to take a photo of a perfect grey and calibrate.

Eyal
  • 5,728
  • 7
  • 43
  • 70