Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 621
DrSAR Avatar asked Feb 18 '11 22:02

DrSAR


People also ask

How do you find the region of interest in image processing in Python?

Python OpenCV – selectroi() Function With this method, we can select a range of interest in an image manually by selecting the area on the image. Parameter: window_name: name of the window where selection process will be shown. source image: image to select a ROI.

How do you find the region of interest in an image?

A region of interest (ROI) is a portion of an image that you want to filter or perform some other operation on. You define an ROI by creating a binary mask, which is a binary image that is the same size as the image you want to process with pixels that define the ROI set to 1 and all other pixels set to 0.


2 Answers

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.

like image 103
DrSAR Avatar answered Sep 28 '22 08:09

DrSAR


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) 
like image 26
otterb Avatar answered Sep 28 '22 09:09

otterb