initial working version

This commit is contained in:
Adien Akhmad 2026-02-21 10:00:02 +07:00
commit 7a95c415e0

88
particle-beads.ijm Normal file
View file

@ -0,0 +1,88 @@
// 1. Ask the user for the input folder
inputDir = getDirectory("Choose Input Directory");
// 2. Create the output folder automatically inside the input folder
outputDir = inputDir + "particle_analyze" + File.separator;
if (!File.exists(outputDir)) {
File.makeDirectory(outputDir);
}
// 3. Prepare the environment (Clear old results/summaries)
run("Clear Results");
if (isOpen("Summary")) {
selectWindow("Summary");
run("Close");
}
list = getFileList(inputDir);
setBatchMode(true); // Run in the background (much faster)
for (i = 0; i < list.length; i++) {
// Process only PNG files
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 the PNG
open(input + filename);
// Create a TIFF filename for the output
basename = File.nameWithoutExtension;
newName = basename + ".tif";
// --- Your recorded steps ---
run("Set Scale...", "distance=2691 known=1000 unit=micron global");
run("Specify...", "width=2691 height=2691 x=476 y=476 constrain");
run("Crop");
// Save the cropped version as TIFF in the particle_analyze folder
saveAs("Tiff", output + newName);
currentImage = getTitle();
// Image Processing for Masking
run("Duplicate...", " ");
setThreshold(0, 85, "raw");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
run("Watershed");
// Analyze Particles (the 'summarize' flag builds the report window)
run("Analyze Particles...", "size=78.5-120 circularity=0.75-1.00 display exclude clear summarize add");
// Close the mask (duplicate)
close();
// Select the cropped TIFF and save it with the ROIs
selectImage(currentImage);
if (roiManager("count") > 0) {
roiManager("Show All without labels");
run("Save");
}
// Close everything to free memory
run("Close All");
}