Skip to content

Channel order for demosaicing #18619

@maro-ros

Description

@maro-ros
System information (version)
  • OpenCV => opencv_python-4.4.0.44-cp37-cp37m-manylinux2014_x86_64
  • Operating System / Platform => Ubuntu 16
  • Compiler => Python 3.7
Detailed description

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)

Issue submission checklist

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions