Display RGB image and histo

77 views
Skip to first unread message

olivie...@gmail.com

unread,
Oct 12, 2015, 8:16:04 AM10/12/15
to pyqtgraph
Hello everyone,

Is it possible to diplay:
  • a RGB image (<type 'numpy.ndarray'> [xSize, ySize, 3] )
  • its histo for each channel (R, G and B)
Thanks.

olivie...@gmail.com

unread,
Oct 12, 2015, 9:33:12 AM10/12/15
to pyqtgraph
First test
I can display the RGB image.
But I can not see the hystogram by channel... Have you an idea ?



# -*- coding: utf-8 -*-


from pyqtgraph.Qt import QtCore, QtGui


import pyqtgraph as pg


import matplotlib.image as mpimg




# Load image from disk and reorient it for viewing


fname = '../../IMAGES/kitten.jpg'    # This can be any photo image file


photo=mpimg.imread(fname)


photo = photo.transpose([1,0,2])




# Create app


app = QtGui.QApplication([])




## Create window with ImageView widget


win = QtGui.QMainWindow()


win.resize(1200,800)


imv = pg.ImageView()


win.setCentralWidget(imv)


win.show()


win.setWindowTitle(fname)




## Display the data


imv.setImage(photo)




## Start Qt event loop unless running in interactive mode.


if __name__ == '__main__':


    import sys


    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):


        QtGui.QApplication.instance().exec_()

Saisissez le code ici...

Second test
I can not display the RGB image. Why ???
How do to display histogram for each channel (R, G and B)  ?



# -*- coding: utf-8 -*-


from pyqtgraph.Qt import QtCore, QtGui


import pyqtgraph as pg


import matplotlib.image as mpimg




# Load image from disk and reorient it for viewing


fname = '../../IMAGES/kitten.jpg'    # This can be any photo image file


photo=mpimg.imread(fname)


photo = photo.transpose([1,0,2])




# Create app


pg.mkQApp()




## Create window with GraphicsLayoutWidget widget


w = pg.GraphicsLayoutWidget()


w.show()


v = w.addViewBox(row=0, col=0)




## Display the data


img = pg.ImageItem(photo)


v.addItem(img)






## Start Qt event loop unless running in interactive mode.


if __name__ == '__main__':


    import sys


    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):


        QtGui.QApplication.instance().exec_()

Saisissez le code ici...



Reply all
Reply to author
Forward
0 new messages