Region-of-interest drawing tool for image analysis (in python)

13.9k views Asked by At

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.

5

There are 5 answers

2
ely On BEST ANSWER

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.

0
DrSAR On

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.

1
NewNewton On

YEAR 2023: You should certainly check out mpl_interactions

What you want is here. It works well with jupyter-notebooks, too.

Example from the official website:

Image Segmentation GIF

Reference: https://mpl-interactions.readthedocs.io (last accessed: 28th of Feb 2023)

0
otterb On

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) 
0
lhcgeneva On

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.