Loop for image sequence

I tried to follow these instructions


and tried several tests
test-1.ijm
input = “/home/tmf/forschung/test/load/”;
output = “/home/tmf/forschung/test/save/”;

setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++)
/home/tmf/forschung/test/scr-awk/histo-ganz(input, output, list[i]);
setBatchMode(false);
message: statement cannot begin with ‘/’ in line 7

in test-2.ijm
line 7 here: home/tmf/forschung/test/scr-awk/histo-ganz(input, output, list[i]);
message: undefined variable in line 7

in test-3.ijm
an additional line: function = “/home/tmf/forschung/scr-awk/save/”;
and line 8 here: histo-ganz(input, output, list[i]);
message: undefined variable in line 8

finally in test-4.ijm
input = “/home/tmf/forschung/test/load/”;
output = “/home/tmf/forschung/test/save/”;
setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++){
run(“8-bit”);
nBins = 256;
getHistogram(value, count, nBins);
run(“Histogram”);
run(“Clear Results”);
for (i=0; i<nBins; i++){
setResult(“Value”, i, value[i]);
setResult(“Count”, i, count[i]);
}
updateResults();
saveAs(“Results”, output + filename);
close();
}
setBatchMode(false);
message: there are no images open

Hi @thomasEins,

welcome to the ImageJ macro world! :wink:

I guess, in your macro tests, you basically only have some issues with opening files the right way. Try to continue with this one:

input = "/home/tmf/forschung/test/load/";
output = "/home/tmf/forschung/test/save/";

list = getFileList(input);
for (i = 0; i < list.length; i++) {
    filename = input + list[i];
    open(filename);
    
    // process your image here
}

Furthermore, you can read more about the macro language here:
https://imagej.nih.gov/ij/developer/macro/macros.html

You might also have a look at a bit more sophisticated ImageJ macro template for processing folders and files:
https://github.com/imagej/imagej-legacy/blob/master/src/main/resources/script_templates/ImageJ_1.x/Batch/Process_Folder.ijm

Cheers,
Robert

thank you Robert, in implementing your suggestion I noticed that I had forgotten a line - embarassed
Cheers, Thomas

1 Like