Processing a folder

Hi, I think this should be a quick one. I am new to this and I am wondering why my processed images are not to be found in the output directory. Can anyone help?

#@ File (label = “Input directory”, style = “directory”) input
#@ File (label = “Output directory”, style = “directory”) output
#@ String (label = “File suffix”, value = “.tif”) suffix


function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);

function processFile(input, output, file) {
makeRectangle(10, 10, 300, 180);

Well in your macro you basically just open the input file:


Create a Rectange selection:

makeRectangle(10, 10, 300, 180);

But then you close the image without saving it:


Computers are very fast but also very stupid ( You need to be very explicit in telling it what to do. So you just save the image then by:

saveAs("Tiff", "/Dir/file.tif");

You can find out what to tell Fiji to do what you want by using the record macro function: Plugins > Macros > Record…

Ah, yes, thank you.

But what if I want to have one .jpg file for each of the processed images?


saveAs(format, path)
Saves the active image, lookup table, selection, measurement results, selection XY coordinates or text window to the specified file path. The format argument must be “tiff”, “jpeg”, “gif”, “zip”, “raw”, “avi”, “bmp”, “fits”, “png”, “pgm”, “text image”, “lut”, “selection”, “results”, “xy Coordinates” or “text”. Use saveAs(format) to have a “Save As” dialog displayed.

1 Like