I have a folder of multiple Tif images, that I wish to analyze the particles, using analyze particles function. I need one channel, with all of its z-stack slices to be analysed and saved into a folder. My problem is that only every second summary and results table is being saved. So if my image has 10 z-stack slices, it saves slice 1, 3, 5, 7 etc. I must just be missing something small! This is in the ImageJ macro language.
// Choose input and output folders
dir1 = getDirectory("Choose Source Directory ");
resultsDir = dir1+"results/";
File.makeDirectory(resultsDir);
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
processFolder(dir1);
function processFolder(dir1){
list = getFileList(dir1);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(dir1 + File.separator + list[i]))
processFolder(dir1 + File.separator + list[i]);
if(endsWith(list[i], ".tif"))
processFile(dir1, dir2, list[i]);
}
}
function processFile(dir1, dir2, file){
open(dir1 + File.separator + file);
// Split channels and rename
title = getTitle();
run("Split Channels");
selectWindow("C2-" + title);
rename("live");
selectWindow("C3-" + title);
rename("dead");
selectWindow("C4-" + title);
rename("total");
//Apply pre-processing filters and threshold live cells
selectWindow("live");
run("Duplicate...", "duplicate"); // Duplicates live channel so accurate thresholding can be done in the following step
rename("duplicate");
selectWindow("live");
run("Gaussian Blur...", "sigma=2 stack");
run("Threshold...");
waitForUser("Adjust threshold, press ok on this pop-up when the threshold has been set. Do not press anything on the threshold screen when finished. Just press ok on action required screen");
run("Make Binary", "method=Default background=Dark calculate black");
//run("Auto Local Threshold", "method=Phansalkar radius=8 parameter_1=0 parameter_2=0 white stack");
run("Fill Holes", "stack");
//run("Watershed", "stack");
run("Stack to Images"); //Makes z-slices individual images
//For every image that is binary, rename the slice and analyze particles
for(z=0; z<nImages; z++){
selectImage(z+1);
if(is("binary")){
name = getTitle();
rename(name + "_" + title);
run("Analyze Particles...", "size=0.50-Infinity show=[Overlay Masks] display clear summarize overlay add");
selectWindow("Summary");
saveAs("Results", dir2 + "Live_Summary_" + z + "_" + title + ".csv");
selectWindow("Results");
saveAs("Results", dir2 + name +"_" + z + "_" + title + ".csv");
close();
}
}
close("live*");
close("duplicate");
run("Close");
close();
// Leave the print statements until things work, then remove them.
print("Processing: " + dir1 + File.separator + file);
print("Saving to: " + dir2);
}