Display RGBA image: got graylevel image instead

38 views
Skip to first unread message

jpmor...@gmail.com

unread,
Aug 19, 2020, 9:02:23 AM8/19/20
to pyqtgraph

Hi All,

I have some issues with color using pyqtgraph.
I have a basic code for displaying a RGBA image.
I am expecting to have a color image but instead I have a graylevel image
Do you see an obvious explanation to this behavior in this code ?

from pyqtgraph.Qt import QtCore, QtGui

import pyqtgraph as pg

import cv2

 

pg.setConfigOptions(imageAxisOrder='row-major')

 

app = QtGui.QApplication([])

## Create window with GraphicsView widget

win = pg.GraphicsLayoutWidget()

win.show()  ## show widget alone in its own window

win.setWindowTitle('pyqtgraph example: ImageItem')

view = win.addViewBox()

view.invertY(True)

 

## lock the aspect ratio so pixels are always square

view.setAspectLocked(True)

 

## Create image item

l_img_item = pg.ImageItem(border='w')

view.addItem(l_img_item)

l_img_item.setCompositionMode(QtGui.QPainter.CompositionMode_Plus)

# l_img_item.setZValue(10)

# l_img_item.setOpacity(0.5)

 

l_image = cv2.imread('_test.png')

l_image = cv2.cvtColor(l_image, cv2.COLOR_RGBA2RGB)

 

## Set initial view bounds

view.setRange(QtCore.QRectF(0, 0, 375, 400))

 

# timer = QtCore.QTimer()

# timer.timeout.connect(self._update)

# timer.start(50)

l_img_item.setImage(l_image, autoLevels=False)

l_img_item.setCompositionMode(QtGui.QPainter.CompositionMode_Plus)

app.exec_()


Thanks for your help


JMA 1

unread,
Aug 19, 2020, 9:12:16 AM8/19/20
to pyqt...@googlegroups.com
Howdy,

What happens if you add the cv2 item to the view after you fully initialize it?
If you use the imread method with an image file does this work correctly?  This may help identify if this is an issue with the un-official openCV release or pyqtgraph
something like: 
     import cv2 as cv
     img = cv.imread(cv.samples.findFile("something.jpg")
     cv.imshow("something", img)

Cheers,
J- 

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/28bcd3c1-bf68-495a-be2d-65e0021f4cd1n%40googlegroups.com.
Message has been deleted

jpmor...@gmail.com

unread,
Aug 19, 2020, 9:18:54 AM8/19/20
to pyqtgraph
Thank you for your pertinent question!
I have been stupid assuming that the image was a color image because it was encoded on 4 channels.
Your simple test made me realize this obvious thing!
Fortunately I will not die after such a shame! :-)

azpa...@gmail.com

unread,
Aug 19, 2020, 9:47:54 AM8/19/20
to pyqtgraph
does  setImage(image, levelMode="rgba", etc.) work for you?

Jerzy Karczmarczuk

unread,
Aug 19, 2020, 11:12:26 AM8/19/20
to pyqt...@googlegroups.com


Le 19/08/2020 à 15:02, jpmor...@gmail.com a écrit :
I have some issues with color using pyqtgraph.
I have a basic code for displaying a RGBA image.
I am expecting to have a color image but instead I have a graylevel image
Do you see an obvious explanation to this behavior in this code ?

It seems that you have partly solved your issue.

I believe that not all, though... You might be surprised, since cv2 uses the BGR colour plane ordering, while most other software -- RGB.

Nice Californian girls will look like, Ehm... Andorians (without horns).


Jerzy Karczmarczuk

/Caen, France/


jpmor...@gmail.com

unread,
Aug 19, 2020, 12:27:38 PM8/19/20
to pyqtgraph
Yes, adding level="rgba" works but it works also without
Message has been deleted

jpmor...@gmail.com

unread,
Aug 19, 2020, 12:31:53 PM8/19/20
to pyqtgraph
Thank you but yes I took that in charge already!

Actually, I love the colors of your picture (I am also a trekkie :-) )
Reply all
Reply to author
Forward
0 new messages