diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..56fd0e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/debug \ No newline at end of file diff --git a/particle-beads.ijm b/particle-beads.ijm index 28414ce..faa27af 100644 --- a/particle-beads.ijm +++ b/particle-beads.ijm @@ -1,13 +1,15 @@ -// 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) +// config - roi styling +roiColor = "yellow"; +roiThickness = 3; +fillColor = "none"; + +// prepare the environment (Clear old results/summaries) run("Clear Results"); if (isOpen("Summary")) { selectWindow("Summary"); @@ -15,10 +17,9 @@ if (isOpen("Summary")) { } list = getFileList(inputDir); -setBatchMode(true); // Run in the background (much faster) +setBatchMode(true); for (i = 0; i < list.length; i++) { - // Process only PNG files if (endsWith(toLowerCase(list[i]), ".png")) { processFile(inputDir, outputDir, list[i]); } @@ -31,7 +32,6 @@ if (isOpen("Summary")) { saveAs("Results", outputDir + "Summary_Report.csv"); } - if (isOpen("Results")) { selectWindow("Results"); run("Close"); @@ -46,43 +46,37 @@ function processFile(input, output, filename) { roiManager("delete"); } - // Open the PNG open(input + filename); - // Create a TIFF filename for the output + // create a filename for the output basename = File.nameWithoutExtension; - newName = basename + ".tif"; + newName = basename + ".png"; - // --- 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 + // prepare binary image for analyzer 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) + run("Watershed"); + run("Analyze Particles...", "size=78.5-120 circularity=0.75-1.00 display exclude clear summarize add"); close(); - // Select the cropped TIFF and save it with the ROIs + // 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("Save"); - } - - // Close everything to free memory + run("Flatten"); + saveAs("PNG", output + newName); + } run("Close All"); } \ No newline at end of file