Skip to content

readbayer color channels are out of order #642

@dschneiderch

Description

@dschneiderch

Describe the bug
readbayer() is producing color images where the bands are out of order and image is rotated. I am actually getting a RGB image back (with bayertype 'BG') which means all the pcv functions are converting it to BGR when displaying, for example.

I tracked down cvtColor bug that seems to exist on and off in opencv from 2.4 -> 4.1 opencv/opencv#4857
The last version on conda forge with the correct behavior is 3.4.2. (did not try 4.x series)

To Reproduce
download https://github.com/danforthcenter/plantcv/files/4314758/Pats.Wheat.Root.Growth_002-0001_A1_2019-06-11_07-19-08.461_0.zip

import cv2
from plantcv import plantcv as pcv
filename='data/images/Pats Wheat Root Growth_002-0001_A1_2019-06-11_07-19-08.461_0.tif'
image_raw=cv2.imread(filename, -1)
img = cv2.cvtColor(image_raw, cv2.COLOR_BayerBG2BGR)
pcv.plot_image(img)

image

Expected behavior

image
or
even better rotated too which happens with opencv 3.4.2
image

Local environment (please complete the following information):
windows 10, conda, pcv 3.10.1 and latest master. seems dependent on opencv >3.4.2

Additional context
2 possible solutions until upstream gets fixed:

  1. limit opencv to 3.4.2

  2. switch the color rendering to color demosaicing package

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions