Importing and displaying a .jpeg using pyqtgraph

31 views
Skip to first unread message

Francisco Gonzalez-Longatt

unread,
May 15, 2019, 5:20:45 AM5/15/19
to pyqtgraph
Dear Group
I am not a top expert in python or even pyqtgraph. However, I am developing a small project where I need to present a .jpeg. Could you please how to do so...
I am using this,

import sys 
import pyqtgraph as pg
import numpy as np
from PIL import Image
import numpy as np



ImgFilename = 'Mapa de Norway.jpg'
def run():
    if not QApplication.instance():
        app = QApplication(sys.argv)
    else:
        app = QApplication.instance() 
    app.exec_()
i = Image.open(ImgFilename)
i = i.transpose(Image.FLIP_TOP_BOTTOM)
i = i.rotate(-45)
imgg = np.asarray(i)
#pg.image(imgg)   # FUNCIONA


imv = pg.ImageView()
imv.show()
imv.setImage(imgg)

However, I do not need Histogram, ROI, Menu, etc...It is just presenting the jpeg.
Looking forward to your advice, responses are much appreciated!
FGL


Kenneth Lyons

unread,
May 15, 2019, 11:30:26 PM5/15/19
to pyqtgraph
An ImageItem will do what you want. Here's an example:

import pyqtgraph as pg
import numpy as
np

app
= pg.mkQApp()

# load your image into a numpy array here...
img_data
= np.random.randn(10, 10)
img
= pg.ImageItem(img_data)

vb
= pg.ViewBox(lockAspect=True, enableMouse=False, enableMenu=False)
vb
.addItem(img)

gv
= pg.GraphicsView()
gv
.setCentralWidget(vb)
gv
.show()

app
.exec_()

High-level documentation on how to use all of these graphics items and such is a bit sparse, but there are examples demonstrating usage of most of them (here: https://github.com/pyqtgraph/pyqtgraph/tree/develop/examples). It might also help to read through some of Qt's graphics view framework documentation to get familiar with the terminology used: https://doc.qt.io/qt-5/graphicsview.html
Reply all
Reply to author
Forward
0 new messages