requires("1.49b"); run("Duplicate...", "title=Binary duplicate"); run("8-bit"); Dialog.create("Custom Stack Threshold"); Dialog.addChoice("Background:", newArray("dark","bright")); Dialog.addNumber("Factor to increase threshold:", 1.15); Dialog.show; mode = Dialog.getChoice; factor = Dialog.getNumber; if (mode=="bright") mode=""; method = "IJ_IsoData " + mode; setOption("BlackBackground", true); for (i=1; i<=nSlices; i++) { setSlice(i); setAutoThreshold(method); getThreshold(lower, upper); if (mode =="dark") lower = lower/factor; else { upper = upper*factor; if (upper>255) upper=255; } setThreshold(lower, upper); run("Analyze Particles...", "show=Masks in_situ slice"); } setSlice(1); resetThreshold;