save the overlay in png

This commit is contained in:
Adien Akhmad 2026-02-21 10:51:15 +07:00
parent 7a95c415e0
commit 9da624879a
2 changed files with 20 additions and 25 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/debug

View file

@ -1,13 +1,15 @@
// 1. Ask the user for the input folder
inputDir = getDirectory("Choose Input Directory"); inputDir = getDirectory("Choose Input Directory");
// 2. Create the output folder automatically inside the input folder
outputDir = inputDir + "particle_analyze" + File.separator; outputDir = inputDir + "particle_analyze" + File.separator;
if (!File.exists(outputDir)) { if (!File.exists(outputDir)) {
File.makeDirectory(outputDir); File.makeDirectory(outputDir);
} }
// 3. Prepare the environment (Clear old results/summaries) // config - roi styling
roiColor = "yellow";
roiThickness = 3;
fillColor = "none";
// prepare the environment (Clear old results/summaries)
run("Clear Results"); run("Clear Results");
if (isOpen("Summary")) { if (isOpen("Summary")) {
selectWindow("Summary"); selectWindow("Summary");
@ -15,10 +17,9 @@ if (isOpen("Summary")) {
} }
list = getFileList(inputDir); list = getFileList(inputDir);
setBatchMode(true); // Run in the background (much faster) setBatchMode(true);
for (i = 0; i < list.length; i++) { for (i = 0; i < list.length; i++) {
// Process only PNG files
if (endsWith(toLowerCase(list[i]), ".png")) { if (endsWith(toLowerCase(list[i]), ".png")) {
processFile(inputDir, outputDir, list[i]); processFile(inputDir, outputDir, list[i]);
} }
@ -31,7 +32,6 @@ if (isOpen("Summary")) {
saveAs("Results", outputDir + "Summary_Report.csv"); saveAs("Results", outputDir + "Summary_Report.csv");
} }
if (isOpen("Results")) { if (isOpen("Results")) {
selectWindow("Results"); selectWindow("Results");
run("Close"); run("Close");
@ -46,43 +46,37 @@ function processFile(input, output, filename) {
roiManager("delete"); roiManager("delete");
} }
// Open the PNG
open(input + filename); open(input + filename);
// Create a TIFF filename for the output // create a filename for the output
basename = File.nameWithoutExtension; basename = File.nameWithoutExtension;
newName = basename + ".tif"; newName = basename + ".png";
// --- Your recorded steps ---
run("Set Scale...", "distance=2691 known=1000 unit=micron global"); run("Set Scale...", "distance=2691 known=1000 unit=micron global");
run("Specify...", "width=2691 height=2691 x=476 y=476 constrain"); run("Specify...", "width=2691 height=2691 x=476 y=476 constrain");
run("Crop"); run("Crop");
// Save the cropped version as TIFF in the particle_analyze folder
saveAs("Tiff", output + newName);
currentImage = getTitle(); currentImage = getTitle();
// Image Processing for Masking // prepare binary image for analyzer
run("Duplicate...", " "); run("Duplicate...", " ");
setThreshold(0, 85, "raw"); setThreshold(0, 85, "raw");
setOption("BlackBackground", true); setOption("BlackBackground", true);
run("Convert to Mask"); run("Convert to Mask");
run("Fill Holes"); run("Fill Holes");
run("Watershed"); 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"); run("Analyze Particles...", "size=78.5-120 circularity=0.75-1.00 display exclude clear summarize add");
// Close the mask (duplicate)
close(); close();
// Select the cropped TIFF and save it with the ROIs // select the cropped image and save it with the ROIs
selectImage(currentImage); selectImage(currentImage);
if (roiManager("count") > 0) { if (roiManager("count") > 0) {
roiManager("deselect");
roiManager("Set Color", roiColor);
roiManager("Set Line Width", roiThickness);
roiManager("Show All without labels"); roiManager("Show All without labels");
run("Save"); run("Flatten");
saveAs("PNG", output + newName);
} }
// Close everything to free memory
run("Close All"); run("Close All");
} }