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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With