Run a macro for several images

Hi all,
I try to create a macro to analyze several images. When I the processing part with the the menu process/batch than it counts the cells wrong. So I want to create a macro with batchfuntion.
I used at first the macro from But here isn’t create an outputfile. So I think it doesn’t work or the czi-File isn’t detected.

I hope you have some hints how to create a macro with batch function. (I use ImageJ 1.53c fiji)

function action(input, output, filename) {
        run("Split Channels");
        setOption("ScaleConversions", true);
        run("Enhance Contrast", "saturated=0.35");
        setMinAndMax(0, 60);
        //setThreshold(8, 255);
        setThreshold(8, 255);
        setOption("BlackBackground", true);
        run("Convert to Mask");
        run("Minimum...", "radius=5");
        run("Analyze Particles...", "size=13-Infinity show=[Overlay Masks] clear summarize");
        saveAs("Jpeg", output + "Image name");

input = "/";
output = "/output/";

list = getFileList(input);
for (i = 0; i < list.length; i++){
        action(input, output, list[i]);

Hi gonzo, welcome to the forum :fist_left:!

It seems that something is going wrong getting your files list. Probably a good idea is to use something like:

// display dialog to ask user for input directory
input = getDir(“Choose a Directory”);

To trouble shoot your macros you can just use

print(“Processing file:”, i);
for instance, to check where the problem occurs. Then you can usually find a way to fix it, or come back here to get help!

Also, for more information on macro writing, check out:

Good luck!


I would recommend trying the BioFormatsImporter plugin while the Macro Recorder is running to see the correct format for opening your CZI files.
Also edited for code formatting.
Also also, +1 for @petebankhead guide.