I'm trying to run through a folder in BatchMode but even when I set it to setBatchMode(true)
(or setBatchMode("hide")
) it still opens the image before setBatchMode("show")
and takes forever to open and process.
It runs "faster" when I don't use BatchMode but it still takes forever to process one image... and i have many to get through
/*
* Macro template to process prepare images in a folder
*/
#@ File (label = "image input directory", style = "directory") imageinput
#@ File (label = "Output", style = "directory") output
processFolder(imageinput);
table_name = "approval table";
Table.create(table_name);
setBatchMode(true)
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(imageinput) {
imagesList = getFileList(imageinput);
imagesList = Array.sort(imagesList);
for (i = 0; i < imagesList.length; i++) {
imagesFilename = substring(imagesList[i], 0, lastIndexOf(imagesList[i], "."));
currentimage = imageinput + File.separator + imagesList[i];
processFile(imagesFilename);
}
}
function processFile(imagesFilename) {
open(currentimage);
run("Select All");
run("Set... ", "zoom=200 x=8640 y=5400");
run("Subtract Background...", "rolling=1 light sliding disable");
run("Brightness/Contrast...");
setMinAndMax(186, 249);
call("ij.ImagePlus.setDefault16bitRange", 8);
run("Apply LUT");
setBatchMode("show")
waitForUser("User to Approve"); //here i check that that i'm okay with the contrast/brightness etc and click approve
current_image = getTitle(); //here i add image name to a list if i think i need to go back and manually review it
approve_review = getBoolean("review?", "yes", "no");
if (approve_review == true) {
approve_review_text = "yes";
}
else {
approve_review_text = "no";
}
s = Table.size; // gets the size (lines) of the current table
Table.set("image", s, current_image);
Table.set("review", s, approve_review_text);
Table.update;
wait(100) ;
setBatchMode("hide")
selectWindow("Results");
saveAs("Text", output + File.separator + "approval_table.csv");
saveAs("Tiff", output + File.separator + imagesFilename + ".tif");
close();
}
Edit: as someone kindly beat me to it - I was given the solution in the imageJ forum where setBatchMode(true)
needs to go right after selecting the directory.
I've also solved the speed issue -
run("Collect Garbage");
after closing the image