I am attempting to put pyqtgraph ROI widgets (information here) on top of a .PNG image. When I import the image into the program, it comes out rotated and flipped the wrong way. I assume this is a bug. To attempt to fix it, I have rotated the image BUT when I do so, my ROI widget goes off of the image. How do I fix this?
Without image rotation:
i = Image.open("del.png")
a = array(i) #converting to numpy array
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
Once I add img1a.rotate(90)
to the code above, the ROI widget goes off the screen. How do I position the image the correct way and have my ROI widget appear normally on top of the image?
The entire code is found below (edited from this example found here.)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
from numpy import array
from PIL import Image
## create GUI
app = QtGui.QApplication([])
w = pg.GraphicsWindow(size=(1000,800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')
text = """text"""
w1 = w.addLayout(row=0, col=0)
label1 = w1.addLabel(text, row=0, col=0)
v1a = w1.addViewBox(row=1, col=0, lockAspect=True)
#img1a = pg.ImageItem(arr)
i = Image.open("del.png")
a = array(i)
img1a = pg.ImageItem(a)
v1a.addItem(img1a)
img1a.rotate(90)
v1a.disableAutoRange('xy')
v1a.autoRange()
rois = []
rois.append(pg.EllipseROI([150, 150], [1, 1], pen=(4,9)))
rois.append(pg.EllipseROI([0, 0], [300, 300], pen=(4,9)))
for roi in rois:
v1a.addItem(roi)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()