IsoCurveItem is slow for large images

69 views
Skip to first unread message

Dig...@gmx.de

unread,
Mar 17, 2017, 5:44:33 AM3/17/17
to pyqtgraph

Hi,

I have an ImageView which resides in a PlotItem (for the grid) and want to draw a number of IsoCurveItems on the ImageItem like in the IsoCurveItem example file. The image is about 1000 x 1000 px. Adding the IsoCurveItems seems to be very slow. I put a 
QApplication.processEvents()
in the loop and can literally watch the curves appear one after another. Is there a way to speed things up for larger number of curves?

Thanks...

Here is some test code:
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets
import numpy as np
import pyqtgraph as pg

app = QtGui.QApplication([])

m = n = 1000
x, y = np.meshgrid(range(m), range(n))
data = (x - m / 2) ** 2 + (y - n / 2) ** 2

win = pg.GraphicsWindow()
vb = win.addViewBox()
img = pg.ImageItem(data)
vb.addItem(img)

for level in np.linspace(data.min(), data.max(), 11)[1:-1]:
    c = pg.IsocurveItem(data=data, level=level, pen=(0, 0, 0))
    c.setParentItem(img)
    QtWidgets.QApplication.processEvents()

if __name__ == '__main__':
    app.exec_()


Vincent Le Saux

unread,
Mar 29, 2017, 12:23:31 AM3/29/17
to pyqtgraph
Hi,

IsoCurveItem is know to be slow (look at the source code). You have two possibilities :
    - write another implementation more efficient (and suggest it on github)
    - use another library for the computation of the isolines. Skimage is a good candidate since the method is written in cython.

I personnaly chose the second solution for my app (do not have the time to write annother method), and it work perfectly. I have observed a nice speed-up (x10 to x100) compared to the implementation of pyqtgraph.

Regards,

Vincent

Dig...@gmx.de

unread,
Apr 21, 2017, 8:15:30 AM4/21/17
to pyqtgraph
Thanks for the skimage hint! I'll try it out...
Reply all
Reply to author
Forward
0 new messages