ImageJ Fill in -macro mode vs -batch mode

From ImageJ documentation, -macro and -batch command line arguments should be very similar. -batch will disable ImageJ GUI and exit ImageJ at the end of the script. run("Fill", "slice"); should have the same output in -macro and -batch mode.

Consider the following minimal working example, mwe.ijm:

open("single-dot.png");
roiManager("Open", "single-dot.roi");

setAutoThreshold("Default dark");
//run("Threshold...");
//setThreshold(0, 133);
setOption("BlackBackground", false);
run("Convert to Mask");

roiManager("Select", 0);  // Select ROI from file
run("Analyze Particles...", "display exclude clear include add");

run("RGB Color");

roiManager("Select", 0);  // Select ROI from Analyze Particles

run("Fill", "slice");

run("Flatten");

saveAs("PNG", "output.png");

input.zip (3.6 KB) has single-dot.png (illustrate below) and single-dot.roi (rectangle region around the white circle).

For

$ imagej --headless --console -eval "print(getVersion());" | tail -n 1
2.1.0/1.53g
$ imagej -macro mwe.ijm && mv output.png macro.png
$ imagej -batch mwe.ijm && mv output.png batch.png

I have macro.png

and batch.png

Is this a bug? Or am I missing something from how -macro and -batch work?

1 Like

I get the same output from the macro in both -macro and -batch mode after I added

setForegroundColor(255, 0, 0); //red

Without this statement, the macro fills the circle with the default foreground color, which can vary.

I did find bugs with the way open(path) and roiManager(“Open”,path) work when ‘path’ is not a full file path. These bugs are fixed in the 1.53h33 daily build.

2 Likes

@Wayne, Thanks for your reply.

I update my copy of ImageJ to 1.53h37 and I added setForegroundColor(255, 0, 0); to the minimal working example that I provided before. I still get the same output that I reported in my first message: -macro has the particle filled with foreground color and -batch has the full ROI from single-dot.roi filled with foreground color.

mwe.ijm:

open("/tmp/macro-vs-batch/single-dot.png");
roiManager("Open", "/tmp/macro-vs-batch/single-dot.roi");

setAutoThreshold("Default dark");
//run("Threshold...");
//setThreshold(0, 133);
setOption("BlackBackground", false);
run("Convert to Mask");

roiManager("Select", 0);  // Select ROI from file
run("Analyze Particles...", "display exclude clear include add");

run("RGB Color");

setForegroundColor(255, 0, 0);

roiManager("Select", 0);  // Select ROI from Analyze Particles

run("Fill", "slice");

run("Flatten");

saveAs("PNG", "output.png");

And the respective output:

$ imagej -macro mwe.ijm && mv output.png macro.png

$ imagej -batch mwe.ijm && mv output.png batch.png

Am I using setForegroundColor() in the wrong place? I’m using ImageJ from Fiji. Is my issue due some modification from Fiji?

Thanks for the help.

This is a Fiji problem. The command

java -jar ij.jar -batch mwe.ijm

works as expected, and it’s much faster.

2 Likes