Selecting a subset of ROIs in the ROI Manager


In one of my ImageJ macros, I am trying to select a subset of ROIs in the ROI Manager.

For example, I have added 10,000 ROIs in my ROI Manager and I need to select all ROIs except the first two. I thought that the following would work, but it throws an error:

roiManager("Select", 2);
roiManager("Select", 9999);

I know that the following does the job:

roiManager("Select", newArray(2,3,4,....,9999));

but, generating such an array (2,3,4,…,9999) seems like a hassle (to me!):

array = newArray(2,3);
for(i=4;i<10000;i++) {
 	array = Array.concat(array,i);

I am curious to know if there are alternative easier way(s) to achieve what I am trying to do?


How about combining Array.getSquence(10000) with Array.slice(array, 2)? Something like this:

roiManager("Select", Array.slice(Array.getSequence(10000), 2));

A command like roiManager("invert selection"); might be a good addition to the macro language (@Wayne?) for cases like yours, as it would let you select indices 0 and 1 and then invert the selection to get all other ROIs selected.

The other supported scripting languages (e.g. Python or Groovy) make it a bit easier to deal with lists/arrays. See for example in Groovy:

#@ RoiManager rm
rm.setSelectedIndexes(2..9999 as int[])

Thanks @Andrew_Shum, I guess I missed the Array.getSequence() command.

Thanks @imagejan for suggestions in other scripting languages!