Stack.getDimensions(width, height, channels, slices, frames); if (!(slices>1&&frames>1)) exit("4D stack expected"); id1 = getImageID(); dir = getDirectory("Choose Destination Directory "); setBatchMode(true); for (i=1; i<=frames; i++) { print(i+"/"+frames); selectImage(id1); run("Duplicate...", "duplicate frames=&i"); id2 = getImageID(); run("Subtract Background...", "rolling=50 stack"); run("Auto Threshold", "method=Max entropy background=Dark calculate black"); run("Z Project...", "projection=[Sum Slices] all"); run("Divide...", "value=255 stack"); run("Enhance Contrast", "saturated=0.35"); run("Fire"); run("Calibration Bar...", "location=[Upper Left] fill=None label=White number=7 font=9 zoom=1.5 bold overlay"); saveAs("tif", dir+IJ.pad(i,3)+".tif"); close(); selectImage(id2); close(); } setBatchMode(false); run("Image Sequence...", "open=&dir use");