I'm trying to read and demosaic raw images in Python using the RawPy module. Unfortunately the module does not provide simple demosaic method, but a complete postprocess function which is not suitable for my case since I want to keep the floating point images, instead of using 8bit uint. I also do not want to get gamma applied, or any other postprocessing, so I end up demosaicing them manually. When I use the raw_pattern method of RawPy object where I have loaded the dng image I get this:
In[23] : raw_image.raw_pattern
Out[23]: array([[0, 1],
[3, 2]], dtype=uint8)
But Adobe's DNG documentation says
Digital Negative Specification
September 2012
CFAPlaneColor
...
Value
See below
Default
0, 1, 2 (red, green, blue)
And I get confused where does that 3 come from? If there is another way to demosaic raw image It's also suitable, since it's easy for me to replace this part of the project.
Thanks is advance!
rawpy (or more correctly, the underlying libraw/dcraw software) treats the two green channels as separate channels. Have a look at https://en.wikipedia.org/wiki/Bayer_filter where you can see that the Bayer filter matrix is made out of 4-pixel squares which have one blue pixel, one red pixel, and two green pixels. The reason for having two green pixels is that the human vision is much more sensitive to green and will notice noise more easily. By adding more green pixels, the noise in the green channel can be reduced during demosaicing/postprocessing.
Instead of doing the demosaicing yourself (which may be quite hard), another option could be to disable all kinds of postprocessing options and output as 16-bit integer image. I used this technique while processing astrophotography images. See this example from the project overview: