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

5

7

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.

Vitals answered 18/2, 2011 at 22:39 Comment(0)
D
3

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.

Disputatious answered 22/2, 2011 at 22:36 Comment(2)
Thanks for the tip: I have had a look but the examples test_* seem a little fragile in some cases. A bit wary to rely in this. I think I might just have to go the homegrown route with matplotlib+pyQt.Vitals
I am starting to rethink my comment from Mar 2011: I now am trying to incorporate pyqtgraph into our operation. It has moved on from 0.9.3 to 0.9.7 and seems a lot more stable and feature-rich (maybe I didn't look hard enough). Thanks @EMS and +1Vitals
V
7

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.

Vitals answered 5/4, 2011 at 23:32 Comment(0)
S
4

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) 
Septuplet answered 22/4, 2014 at 15:48 Comment(0)
D
3

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.

Disputatious answered 22/2, 2011 at 22:36 Comment(2)
Thanks for the tip: I have had a look but the examples test_* seem a little fragile in some cases. A bit wary to rely in this. I think I might just have to go the homegrown route with matplotlib+pyQt.Vitals
I am starting to rethink my comment from Mar 2011: I now am trying to incorporate pyqtgraph into our operation. It has moved on from 0.9.3 to 0.9.7 and seems a lot more stable and feature-rich (maybe I didn't look hard enough). Thanks @EMS and +1Vitals
T
2

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)

Togs answered 28/2, 2023 at 12:57 Comment(1)
do you know how to work with the 'display' comment in IDE like pycharm? the example seems to be working with ipynotebooks.Tatary
C
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.

Camus answered 5/4, 2017 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.