New roi looping style in ImageJ/Fiji

Dear friends of ImageJ/Fiji scripting,

Just to let you know that you can now since the latest daily build version of ImageJ, directly loop over the roi in the Roi Manager without having to deal with the roi count and index :wink:

This concerns the scripting languages but unfortunately not the macro language (as far as I know).
The previous method is still usable, this new functionality wont break any existing code.

Here is a screencast from the related wiki section. Previous method a the top, new one below.

For the curious, see this PR for the changes to the source code.

11 Likes

Finally! Thank you

Mafalda

2 posts were split to a new topic: Updating ROIs in RoiManager after cropping an image

To add to that, previously it was already possible using RoiManager#getRoisAsArray():

#@ RoiManager rm

for roi in rm.getRoisAsArray():
  print roi

… and for the selected ROIs only:

#@ RoiManager rm

for roi in rm.getSelectedRoisAsArray():
  print roi

So while I see that this new addition makes the code a bit shorter, I think that the API is not necessarily more concise: when iterating over a RoiManager object, would everyone expect looping over all ROIs or the selected ROIs only?

By just writing ‘for roi in rm’ you lose that explicit information.

3 Likes