2010-03-22 05:48:52 +00:00
|
|
|
#!/usr/bin/python -i
|
|
|
|
# -*- coding: utf-8 -*-
|
2010-03-22 06:21:56 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
|
|
|
import sys, os
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
|
2010-03-22 05:48:52 +00:00
|
|
|
from scipy import zeros
|
2010-03-22 06:21:56 +00:00
|
|
|
from pyqtgraph.graphicsWindows import *
|
|
|
|
from pyqtgraph.graphicsItems import *
|
|
|
|
from pyqtgraph.widgets import *
|
|
|
|
from pyqtgraph.PlotWidget import *
|
2010-07-25 04:33:26 +00:00
|
|
|
from pyqtgraph.functions import mkPen
|
2010-03-22 05:48:52 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
app = QtGui.QApplication([])
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
class Win(QtGui.QMainWindow):
|
|
|
|
pass
|
|
|
|
|
|
|
|
w = Win()
|
2010-07-24 18:29:09 +00:00
|
|
|
v = GraphicsView(useOpenGL=False)
|
2010-03-22 05:48:52 +00:00
|
|
|
v.invertY(True)
|
|
|
|
v.setAspectLocked(True)
|
|
|
|
v.enableMouse(True)
|
|
|
|
v.autoPixelScale = False
|
|
|
|
|
|
|
|
w.setCentralWidget(v)
|
|
|
|
s = v.scene()
|
2010-07-25 04:33:26 +00:00
|
|
|
v.setRange(QtCore.QRect(-2, -2, 220, 220))
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
arr = ones((100, 100), dtype=float)
|
|
|
|
arr[45:55, 45:55] = 0
|
|
|
|
arr[25, :] = 5
|
|
|
|
arr[:, 25] = 5
|
|
|
|
arr[75, :] = 5
|
|
|
|
arr[:, 75] = 5
|
|
|
|
arr[50, :] = 10
|
|
|
|
arr[:, 50] = 10
|
|
|
|
|
|
|
|
im1 = ImageItem(arr)
|
|
|
|
im2 = ImageItem(arr)
|
|
|
|
s.addItem(im1)
|
|
|
|
s.addItem(im2)
|
|
|
|
im2.moveBy(110, 20)
|
|
|
|
im3 = ImageItem()
|
|
|
|
s.addItem(im3)
|
|
|
|
im3.moveBy(0, 130)
|
|
|
|
im3.setZValue(10)
|
|
|
|
im4 = ImageItem()
|
|
|
|
s.addItem(im4)
|
|
|
|
im4.moveBy(110, 130)
|
|
|
|
im4.setZValue(10)
|
|
|
|
|
2010-07-25 04:33:26 +00:00
|
|
|
pi1 = PlotItem()
|
|
|
|
s.addItem(pi1)
|
|
|
|
pi1.scale(0.5, 0.5)
|
|
|
|
pi1.setGeometry(0, 170, 300, 100)
|
|
|
|
|
|
|
|
lastRoi = None
|
|
|
|
|
|
|
|
def updateRoi(roi):
|
|
|
|
global im1, im2, im3, im4, arr, lastRoi
|
|
|
|
if roi is None:
|
|
|
|
return
|
|
|
|
lastRoi = roi
|
|
|
|
arr1 = roi.getArrayRegion(im1.image, img=im1)
|
|
|
|
im3.updateImage(arr1, autoRange=True)
|
|
|
|
arr2 = roi.getArrayRegion(im2.image, img=im2)
|
|
|
|
im4.updateImage(arr2, autoRange=True)
|
|
|
|
updateRoiPlot(roi, arr1)
|
|
|
|
|
|
|
|
def updateRoiPlot(roi, data=None):
|
|
|
|
if data is None:
|
|
|
|
data = roi.getArrayRegion(im1.image, img=im1)
|
|
|
|
if data is not None:
|
|
|
|
roi.curve.updateData(data.mean(axis=1))
|
|
|
|
|
|
|
|
#def updatePlot(roi)
|
|
|
|
|
|
|
|
rois = []
|
|
|
|
rois.append(TestROI([0, 0], [20, 20], maxBounds=QtCore.QRectF(-10, -10, 230, 140), pen=mkPen(0)))
|
|
|
|
rois.append(LineROI([0, 0], [20, 20], width=5, pen=mkPen(1)))
|
|
|
|
rois.append(MultiLineROI([[0, 50], [50, 60], [60, 30]], width=5, pen=mkPen(2)))
|
|
|
|
rois.append(EllipseROI([110, 10], [30, 20], pen=mkPen(3)))
|
|
|
|
rois.append(CircleROI([110, 50], [20, 20], pen=mkPen(4)))
|
|
|
|
rois.append(PolygonROI([[2,0], [2.1,0], [2,.1]], pen=mkPen(5)))
|
|
|
|
for r in rois:
|
|
|
|
s.addItem(r)
|
|
|
|
c = pi1.plot(pen=r.pen)
|
|
|
|
r.curve = c
|
|
|
|
r.connect(r, QtCore.SIGNAL('regionChanged'), updateRoi)
|
|
|
|
|
|
|
|
def updateImage():
|
|
|
|
global im1, arr, lastRoi
|
|
|
|
r = abs(random.normal(loc=0, scale=(arr.max()-arr.min())*0.1, size=arr.shape))
|
|
|
|
im1.updateImage(arr + r)
|
|
|
|
updateRoi(lastRoi)
|
|
|
|
for r in rois:
|
|
|
|
updateRoiPlot(r)
|
|
|
|
|
|
|
|
|
|
|
|
t = QtCore.QTimer()
|
|
|
|
t.connect(t, QtCore.SIGNAL('timeout()'), updateImage)
|
|
|
|
t.start(50)
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
w.show()
|
|
|
|
app.exec_()
|