Skip to content, Skip to search

Changes

TrakEM2 Scripting

622 bytes added, 14:28, 19 June 2012
Extract areas from an arealist and put them as ROIs in ImageJ's ROI Manager
run()
</source>
 
 
Notice that python (and jython) lets you use object instance methods as first-class functions, and contructors as well. This enables us to rewrite the "putAreas" function in a functional way, without using any temporary variables and without any if/else logic:
 
<source lang="python">
def putAreas(arealist):
""" Take all areas of an AreaList and put them in the ROI Manager."""
def put(arealist):
map(getRoiManager().addRoi,
map(ShapeRoi,
filter(lambda area: not area.isEmpty(),
filter(None,
map(arealist.getAreaAt, arealist.getLayerRange())))))
</source>
Emailconfirmed, uploaders
653
edits