Display ROIs from RoiManager only for the current slice


I am trying to display ROIs, which I added to ROIManager:

//This code runs in nested loops to add ROIs belonging to different z slice to the RoiManager.
OvalRoi roi = new OvalRoi(x, y, 3, 3);
roi.setStrokeColor(new Color(255, 255, 0));
roi.setPosition(z); OR roi.setPosition(channel, z, frame);
rm.add(ij, roi, i);

rm.runCommand("Show All");

Then I would like to show all the ROIs only on the current slice. However, it shows all the ROIs (even with different z postition).
I can do it manually, but is there a correct and easy way to do it?

Hi SarenT,
have you already tried with this command?

rm.runCommand("Associate", "true"); // you are telling to roi manager to associate roi with slices

I think that it works.
Have a nice day,


Hi emartini,

I did not try it before (seen nowhere) but it works perfectly! Thanks a lot!
You have a nice day too,

1 Like

You can get the commands required to set the ROI Manager options by starting the Recorder (Plugins > Macros > Record…) in Java mode and then running More > Options… in the ROI manager:

rm.runCommand("Associate", "true");
rm.runCommand("Centered", "false");
rm.runCommand("UseNames", "false");