Multiple ROI Manager

Hi all,

Is it possible to have multiple ROI Manager in a script ? I have a jython script where I have rm1 = RoiManager() and rm2 = RoiManager() but it still gives me weird issues etc…

Thanks.

As far as I know one can only have 1 ROI Manager window per instance of ImageJ.
Maybe in the ImageJ2 world there is a solution for that…

When I needed different sets of ROIs I usually save them and the load them again when needed.

Sure you can, unless you display them, because there can be only a single ROI Manager window.

The problem is with your constructors. If you look at the Javadoc of RoiManager, you’ll find:

RoiManager()
Opens the “ROI Manager” window, or activates it if it is already open.

So by using this constructor twice, you are referring to the same ROI Manager instance.
Instead, you can use the alternative constructor:

RoiManager(boolean b)
Constructs an ROIManager without displaying it.

Here’s a (Groovy) script that illustrates this:

import ij.plugin.frame.RoiManager
import ij.gui.Roi

rm1 = new RoiManager(false)
rm2 = new RoiManager(false)

rm1.addRoi(new Roi(0,0,10,10))
rm1.addRoi(new Roi(0,0,20,30))
rm2.addRoi(new Roi(10,10,10,10))
rm2.addRoi(new Roi(10,10,20,30))
rm2.addRoi(new Roi(10,10,40,15))

println "RM1: " + rm1.getRoisAsArray()
println "RM2: " + rm2.getRoisAsArray()

NB: Mind that in Python, you’ll have to call the constructor as rm1 = RoiManager(False)

6 Likes

Perfect ! Thank you both !

I tried with having one displayed and creating one not displayed but it didn’t work. Having them both hidden fixed it !

Thanks again :slight_smile:

2 Likes