Applying the macro to a stack of images

Used the following macro for segmentation but it seems to only process the first image. Tried process_all for some functions and it still does not apply to the stack. Can anybody help me to figure out a way to apply the macro for he entire stack of images.

run("Enhance Contrast...", "saturated=0.3 normalize");
run("Distance Transform Watershed", "distances=[Borgefors (3,4)] output=[32 bits] normalize dynamic=1 connectivity=4");
setOption("ScaleConversions", true);
setAutoThreshold("Default dark");
setThreshold(1, 255);
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
run("Enhance Contrast", "saturated=0.35");
run("Apply LUT");
setAutoThreshold("Default dark");
setThreshold(255, 255);
run("Convert to Mask");
run("Watershed Irregular Features", "erosion=11 convexity_threshold=0 separator_size=0-Infinity");
run("Distance Transform Watershed", "distances=[City-Block (1,2)] output=[16 bits] normalize dynamic=11 connectivity=4");

You can e.g., use the Batch Process option if you have a stack, see:

Should also be working with an already opened stack (or VirtualStack).

Or you can extend your macro to iterate over all slices (your macro applies the operations on the current image slice only). Here a simple example:

for (n=1; n<=nSlices; n++) {
1 Like