我有一个包含多个 Tif 图像的文件夹,我希望使用分析粒子功能来分析粒子。我需要一个通道,其所有 z 堆栈切片都经过分析并保存到一个文件夹中。我的问题是只保存了每隔一秒的摘要和结果表。因此,如果我的图像有 10 个 z 堆栈切片,它会保存切片 1、3、5、7 等。我一定只是遗漏了一些小东西!这是在 ImageJ 宏语言中。
// 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);
}