Rawpy raw image pattern

3.7k views Asked by At

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!

1

There are 1 answers

0
letmaik On BEST ANSWER

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:

with rawpy.imread(path) as raw:
    rgb = raw.postprocess(gamma=(1,1), no_auto_bright=True, output_bps=16)
imageio.imsave('linear.tiff', rgb)