Batch Stack Focusing
Posted by AC17 on Mar 27, 2017; 12:08pm
URL: http://imagej.273.s1.nabble.com/Batch-Stack-Focusing-tp5018376.html
Hi all,
This is my first time attempting to write a macro in image J. I would really appreciate your help with this…
I have a main directory with multiple subdirectories. Each subdirectory contains multiple images (z stacks). I would like to write a code which will take my main directory and open a subdirectory , open all the images in that subdirectory, stack the images, run the stack focusing plugin and then save the stack in the corresponding folder. I would like to loop this so that all the subdirectories within my main directory are processed.
This is what I have so far. This code runs for a few minutes but I then can’t find my saved stacks.
dir = getDirectory("Choose Main Directory");
setBatchMode(true);
count = 0;
countFiles(dir);
n = 0;
processFiles(dir);
print(count+" files processed");
function countFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
countFiles(""+dir+list[i]);
else
count++;
}
}
function processFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFiles(""+dir+list[i]);
else {
showProgress(n++, count);
path = dir+list[i];
processFile(path);
}
}
}
function processFile(path) {
for (i=0; i<list.length; i++)
open(path);}
{
run("Images to Stack", "name=Stack title=[] use");
run("Stack Focuser ", "enter=11");
saveAs("Tiff", "stack" );
close();
}
Many thanks for your help!
Amy