Z-stack remove mean background intensity on each frame

Dear all,
I have a Z-stack of 153 frames.
I want to thresholdind the background of each frame and then measure the mean intensity and remove this value on each frame.

I made this macro but it did not work:

run("32-bit");
setBatchMode(true); // to speed up the script function below
setAutoThreshold("Otsu dark");
setOption("BlackBackground", true);
run("Set Measurements...", "area mean standard limit display redirect=None decimal=3");
for(i=1 ; i<=153 ; i++) {
		Stack.setFrame(i);
		List.setMeasurements();
		background = List.getValue("Mean");
		run("Subtract...", "value="+background);
}
resetThreshold;
setBatchMode(false);

any ideas?

Thanks
Miguel

Hi @mvizoso,

Sharing your code helps, but the remark “it did not work” doesn’t.
Maybe you can be a bit more specific about what did not work, as we don’t have your image stack.

We don’t need to have the entire stack, one slice or two slices which cause the “it” in “it did not work” would be enough.

Setting batch mode to true, by the way, is usually done after all bugs have been removed from your macro, as updating the image sometimes introduces bugs; that is the case if the macro relies on visible outcome in certain processing steps, is my experience.