// Macro “CountAndConfirm” by Kevin Trout // Add or remove "run("Fill Holes");" lines as appropriate for image conditions macro "CountAndConfirm [q]" { function PrimaryMethod() { roiManager("reset"); run("Duplicate...", "title=[Counting Window]"); run("Make Binary"); // run("Fill Holes"); run("Ultimate Points"); run("Make Binary"); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize add"); close(); roiManager("Show All"); if(getBoolean("Satisfied with Result?\n \"Yes\" to continue with next image in folder.\n \"No\" to repeat analysis with manual threshold.\n \"Cancel\" to end batch.")) { run("Open Next"); PrimaryMethod(); } else { n=Table.size("Summary"); Table.deleteRows(n-1,n-1,"Summary"); SecondaryMethod(); } } function SecondaryMethod() { roiManager("reset"); run("Duplicate...", "title=[Counting Window]"); run("8-bit"); run("Threshold..."); title = "User Input Required"; msg = "Manually threshold, then click \"OK\"."; waitForUser(title, msg); run("Make Binary"); run("Fill Holes"); run("Ultimate Points"); run("Make Binary"); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize add"); close(); roiManager("Show All"); if(getBoolean("Satisfied with Result?\n \"Yes\" to continue with next image in folder.\n \"No\" to repeat analysis with manual threshold.\n \"Cancel\" to end batch.")) { run("Open Next"); PrimaryMethod(); } else { n=Table.size("Summary"); Table.deleteRows(n-1,n-1,"Summary"); SecondaryMethod(); } } PrimaryMethod(); }