Question

In an effort to move away from IDL and Matlab, I'm exploring what kind of tools I need to implement in python/scipy et al. One common feature is to display medical images and outline regions of interest (e.g. defroi in IDL or, it's GIU version, xroi). In chaco and matplotlib there are examples of the LassoSelection tool that comes close but is not quite right for my needs (I would like to click-click-click a polygon rather than drag a cursor).

Are there existing tools that can do this or would I need to extend and customize existing classes? In either case, pointers in the right direction would be helpful.

Was it helpful?

Solution

I think you might be able to use PyQTGraph for this purpose, https://launchpad.net/pyqtgraph. I've used it only sparingly, as it has fewer innate options than matplotlib, but it's pretty quick and it does have some built-in widgets for the kind of ROI selection you're interested in. You'll probably find yourself building custom plotting routines that merge matplotlib with PyQTGraph, though, which can cause headaches if the formats are different, etc. It can lead to more bookkeeping, but might solve your problem.

OTHER TIPS

It appears the matplotlib is not that suitable when shooting for interactive data vsiualization that includes features like region-of-interest drawing. Although of course it does deal with event handling etc.

The best I could come up with so far is an impressive effort under the name of guiqwt. It is based on PyQwt and has in addition quite a list of (fairly easy-to-satisfy) dependencies. A quick glance at their test examples of image visualization shows a handy toolset to build upon. It was easy to install and run these examples. Time will tell how easy it is to integrate in my own work.

Now matplotlib has a nice widget called "LassoSelector" which made free polygon drawing very easy.

Sample code here: http://matplotlib.org/examples/widgets/lasso_selector_demo.html

My minimalistic version:

from pylab import *
from matplotlib.widgets import LassoSelector

fig, ax = plt.subplots()
ax.imshow(np.random.randint(0,255,(255,255)), cmap='gray')

def onselect(verts):
    print verts

lasso = LassoSelector(ax, onselect)

subplots_adjust(left=0.1, bottom=0.1) 

There's a nice tool that does exactly what you want by jdoepfert available on github. Performance was a bit slow on my machine, but if you comment out the motion_notify_event it works like a charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top