From 7a95c415e0255174628bb782c7649fa7dc341082 Mon Sep 17 00:00:00 2001 From: Adien Akhmad Date: Sat, 21 Feb 2026 10:00:02 +0700 Subject: [PATCH] initial working version --- particle-beads.ijm | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 particle-beads.ijm diff --git a/particle-beads.ijm b/particle-beads.ijm new file mode 100644 index 0000000..28414ce --- /dev/null +++ b/particle-beads.ijm @@ -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"); +} \ No newline at end of file