synchronizing two imageview widgets

328 views
Skip to first unread message

Dirk Boonzajer Flaes

unread,
Dec 16, 2015, 12:15:51 PM12/16/15
to pyqtgraph
Hi there,

I'd like to analyze two linked images (they are amplitude and phase of an electric field) in a stack of images. Therefore I'd like to synchronize the x, y and t axes of an imageview. To set up something like that, Islightly adapted the example code:


import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np

## Create window with two ImageView widgets
win = QtGui.QMainWindow()
win.resize(800,800)
win.setWindowTitle('pyqtgraph example: DataSlicing')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
imv1 = pg.ImageView(view=pg.PlotItem())
imv2 = pg.ImageView(view=pg.PlotItem())
l.addWidget(imv1, 0, 0)
l.addWidget(imv2, 1, 0)
# link the two views
imv1.view.setXLink(imv2.view)
imv1.view.setYLink(imv2.view)
win.show()

def display_amp_phase(E):
    amp = abs(E)
    phase = np.angle(E)
   
    imv1.setImage(amp)
    imv2.setImage(phase)
   

display_amp_phase(exp(1j*np.random.rand(5,1000,1000)))



However, there is no such function as setTLink to make sure that when scrolling through the stack of images both of them scroll to the same image. How do I do that? I found out that there is a
imv2.timeLine.value()
and
imv2.timeLine.setValue,

so somehow they need to be linked together, but how do I set that up?

regards,

Dirk Boonzajer

vas...@gmail.com

unread,
Dec 16, 2015, 10:49:38 PM12/16/15
to pyqt...@googlegroups.com
Maybe to do that as update if there is no similar link function:


import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np

app = QtGui.QApplication([])

## Create window with two ImageView widgets
win = QtGui.QMainWindow()
win.resize(800,800)
win.setWindowTitle('pyqtgraph example: DataSlicing')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
imv1 = pg.ImageView(view=pg.PlotItem())
imv2 = pg.ImageView(view=pg.PlotItem())
l.addWidget(imv1, 0, 0)
l.addWidget(imv2, 1, 0)
# link the two views
imv1.view.setXLink(imv2.view)
imv1.view.setYLink(imv2.view)
win.show()

def display_amp_phase(E):
    amp = abs(E)
    phase = np.angle(E)
  
    imv1.setImage(amp)
    imv2.setImage(phase)

def update():
    v = imv1.timeLine.value()
    imv2.timeLine.setValue(v)


display_amp_phase(np.exp(1j*np.random.rand(5,1000,1000)))

timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)


if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()





--
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/04dc31ad-4760-47c0-ad47-f54fc276ef38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dirk Boonzajer

unread,
Dec 17, 2015, 4:34:12 AM12/17/15
to pyqt...@googlegroups.com
Hi Vasske,

Thanks for the swift reply. It almost works. It works properly as long as I scroll (or use the keys) in the upper image, but I cannot change the frame I'm examining from the bottom image. Would it be possible to truly link the two? Or maybe we can map the keyboard keys to the other frame, and disable the second slider altogether (I do not need any ROI info).

regards,

Dirk
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/Dw7akoWTAwo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CAD_qyJqdwgCyxP388c6KyhxvtkaKajejD%2B9QHKBgKZKtEgCpcw%40mail.gmail.com.

Luke Campagnola

unread,
Dec 21, 2015, 3:04:20 AM12/21/15
to pyqt...@googlegroups.com
Here's an easy example:

import pyqtgraph as pg
pg.mkQApp()
v1 = pg.image(pg.np.random.normal(size=(100, 100, 100)))
v2 = pg.image(pg.np.random.normal(size=(100, 100, 100)))

v2.sigTimeChanged.connect(v1.setCurrentIndex)
v1.sigTimeChanged.connect(v2.setCurrentIndex)


--
Reply all
Reply to author
Forward
0 new messages