RAW Image cvtColor debayer
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)
Using this code:
import rawpy
import cv2
path = 'android_test.dng'
raw = rawpy.imread(path)
rawrgb = raw.raw_image
rgb = raw.postprocess()
plt.imshow(rgb)
plt.show(block=True)
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)
plt.imshow(dergb)
plt.show(block=True)
but I get this as the output image:
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.