Say "OK" to ImageJ/Fiji ROI Manager “Apply changes to all selections” from macro

Consider the following minimal example of ImageJ/Fiji macro:

run("Particles");
run("Analyze Particles...", "display exclude clear include add");
run("Select All");
roiManager("Set Line Width", 3);
saveAs("Jpeg", "/tmp/particles.jpg");
run("Quit");

When I call the macro using

$ imagej -macro minimal-example.ijm 

ImageJ/Fiji will stop and prompt the user with

apply-changes

ImageJ/Fiji ROI Manager “Apply changes to all selections” window is due

roiManager("Set Line Width", 3);

How can I say “OK” to ROI Manager from my macro? Thanks!

1 Like

I noticed that ImageJ/Fiji ROI Manager will not prompt me if I select a subset of the ROI items. The solution that I found so far is to replace

run("Select All");
roiManager("Set Line Width", 3);

with

for (i=0; i<roiManager("count"); i++) {
    roiManager("Select", i);
    RoiManager.setGroup(0);
    RoiManager.setPosition(0);
    roiManager("Set Line Width", 3);
}

Am I missing something here? I would like to avoid to have the for-loop in my macro file. Thanks!

1 Like

Dear Raniere,
I can’t reproduce your problem. Using your macro code in ImageJ on a PC runs without a dialogue pop-up. However, I think there is a mistake in your code. The run(“Select All”) command does not select all ROIs in the ROI manager, but creates a selection of the whole image.
If you want to select all ROIs in the ROI manager you need to use roiManager(“Deselect”);
This will deselect any ROI and when no ROI is selected, any ROI manager commands will be applied to all ROIs.
The modified code below changes the line width for all ROIs to 3.
Good luck,
Volko

run("Particles");
run("Analyze Particles...", "display exclude clear include add");
roiManager("Deselect");
roiManager("Set Line Width", 3);

Dear Volko,

Thanks for your reply.

I tested the code that you provided and I still encounter the prompt window as illustrated in the following GIF:

$ ImageJ --headless --console -eval "print(getVersion());" | tail -n 1
2.1.0/1.53g

Hi there, I think it would be easier if someone share how to use it correctly because I misunderstood this smile3

Hi @raniere.silva,
I am not able to reproduce this problem but it would be better in this case to use an overlay, as in the following example:

  run("Particles");
  setThreshold(255,255);
  run("Analyze Particles...", " show=Overlay  clear include");
  resetThreshold;
  Overlay.setStrokeWidth(3);
  Overlay.setStrokeColor("cyan");
  Overlay.drawLabels(false)
  saveAs("Jpeg", "/tmp/particles.jpg");

Without the setThreshold(255,255) the particle analyzer will fail if “Black background” in the Process>Binary>Options dialog is enabled.

Another advantage to using an overlay is they work in headless mode, unlike the ROI Manager.