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 https://imagej.nih.gov/ij/macros/BatchProcessFolders.txt. 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) {
        imageTitle=getTitle();
        open("czi")
        run("Split Channels");
        selectWindow("C1-"+imageTitle);
        setOption("ScaleConversions", true);
        run("8-bit");
        //run("Brightness/Contrast...");
        run("Enhance Contrast", "saturated=0.35");
        setMinAndMax(0, 60);
        //run("Threshold...");
        //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");
        close();
        }

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

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

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”);

(https://imagej.net/developer/macro/functions.html#getDirectory)
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!

2 Likes

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.