Ask Your Question

Revision history [back]

Pixel order for demosaicing

Heyho,

If I create a bayer pattern (e.g. ndarray:(128,128)) with the pattern RGGB

RG RG ...
GB GB ...

255 0   255 0
0   0     0 0

I would expect that this will be converted to a pure red image (e.g. ndarray:(128,128, 3)) using opencv demosaicing (COLOR_BAYER_RG2BGR). Unfortunately the result is a blue image (BGR ordering), so output[:,:,0] == 255 which would be right if the output would have RGB ordering but I explicitly used COLOR_BAYER_RG2BGR!

Steps to reproduce

import numpy as np
import cv2

rggb = np.zeros((128, 128), np.uint8)
rggb[::2, ::2] = 255
bgr_debayered = cv2.demosaicing(rggb, cv2.COLOR_BAYER_RG2BGR)
cv2.imwrite("debayered_should_be_red_but_is_blue.png", bgr_debayered)

Any help would be appreciated to understand the change in channel ordering here.