82 lines
No EOL
2.1 KiB
Text
82 lines
No EOL
2.1 KiB
Text
inputDir = getDirectory("Choose Input Directory");
|
|
outputDir = inputDir + "particle_analyze" + File.separator;
|
|
if (!File.exists(outputDir)) {
|
|
File.makeDirectory(outputDir);
|
|
}
|
|
|
|
// config - roi styling
|
|
roiColor = "yellow";
|
|
roiThickness = 3;
|
|
fillColor = "none";
|
|
|
|
// prepare the environment (Clear old results/summaries)
|
|
run("Clear Results");
|
|
if (isOpen("Summary")) {
|
|
selectWindow("Summary");
|
|
run("Close");
|
|
}
|
|
|
|
list = getFileList(inputDir);
|
|
setBatchMode(true);
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
if (endsWith(toLowerCase(list[i]), ".png")) {
|
|
processFile(inputDir, outputDir, list[i]);
|
|
}
|
|
}
|
|
|
|
setBatchMode(false);
|
|
|
|
if (isOpen("Summary")) {
|
|
selectWindow("Summary");
|
|
saveAs("Results", outputDir + "Summary_Report.csv");
|
|
}
|
|
|
|
if (isOpen("Results")) {
|
|
selectWindow("Results");
|
|
run("Close");
|
|
}
|
|
print("Done! Files and summary saved to: " + outputDir);
|
|
|
|
function processFile(input, output, filename) {
|
|
|
|
// Clear ROI Manager for each new image
|
|
if (roiManager("count") > 0) {
|
|
roiManager("deselect");
|
|
roiManager("delete");
|
|
}
|
|
|
|
open(input + filename);
|
|
|
|
// create a filename for the output
|
|
basename = File.nameWithoutExtension;
|
|
newName = basename + ".png";
|
|
|
|
run("Set Scale...", "distance=2691 known=1000 unit=micron global");
|
|
run("Specify...", "width=2691 height=2691 x=476 y=476 constrain");
|
|
run("Crop");
|
|
|
|
currentImage = getTitle();
|
|
|
|
// prepare binary image for analyzer
|
|
run("Duplicate...", " ");
|
|
setThreshold(0, 85, "raw");
|
|
setOption("BlackBackground", true);
|
|
run("Convert to Mask");
|
|
run("Fill Holes");
|
|
run("Watershed");
|
|
run("Analyze Particles...", "size=78.5-120 circularity=0.75-1.00 display exclude clear summarize add");
|
|
close();
|
|
|
|
// select the cropped image and save it with the ROIs
|
|
selectImage(currentImage);
|
|
if (roiManager("count") > 0) {
|
|
roiManager("deselect");
|
|
roiManager("Set Color", roiColor);
|
|
roiManager("Set Line Width", roiThickness);
|
|
roiManager("Show All without labels");
|
|
run("Flatten");
|
|
saveAs("PNG", output + newName);
|
|
}
|
|
run("Close All");
|
|
} |