RAW Image cvtColor debayer

asked 2017-08-06 18:01:05 -0500

I have a .dng test image. I am working in python and so can load the raw image successfully using rawpy, as shown here. (link to the image)

image description

Using this code:

import rawpy
import cv2
path = 'android_test.dng'
raw = rawpy.imread(path)
rawrgb = raw.raw_image
rgb = raw.postprocess()

The raw instance contains an unprocessed raw.raw_image which is the bayer 2D array data. I want to try and reproduce the image that raw.postprocess() produces, but using opencv methods. This is because I eventually want to process custom RAW images which rawpy does not recognise.

So using the raw.raw_image data I have tried this:

dergb = cv2.cvtColor(rawrgb, cv2.COLOR_BayerBG2RGB)

but I get this as the output image:

image description

I have played around with the different cv2.COLOR_BayerC1C22RGB fields, but I still get this strange colourspace. I realise that the .dng contains metadata in the header which includes all kinds of colorMatrices, but my understanding is that these are more for calibrating the colour, not required in implementing this fundemental step.

I would appreciate any help, techniques or suggestions.

edit retag flag offensive close merge delete