Adjust intensity in Z stack individual slides

Dear all,
I have a Z stack in which I would like to correct the intensity of each frame.

The idea is to measure the mean intensity of each frame and use a cutoff value to setup the minAndMax values. I wrote a macro but it does not work. It ajusts the minAndMax values of each frame according with the min and max values of the last slide (which is a black slide).

This is my macro:

adjustBackground();
function adjustBackground(){
run(“Set Measurements…”, “area mean standard min display redirect=None decimal=3”);
slices=nSlices();
for(i=1 ; i<=slices ; i++) { //function to adjust the bright field background according with the initial mean intensity (cutoff 5).
setSlice(i);
List.setMeasurements();
background = List.getValue(“Mean”);
min = List.getValue(“Min”);
max = List.getValue(“Max”);
if(background<=8)
setMinAndMax(min, 80); // for dark bright field
else
setMinAndMax(min/1.2, max);// for bright bright field
}
}

I hope someone can help me to understand why is not working. I guess is something wrong in the code.

Thanks
Miguel

Hi @mvizoso,

Would this macro do the trick?

adjustBackground
adjustBackground();

function adjustBackground(){
	run("Set Measurements...", "area mean standard modal min display redirect=None decimal=3");
	slices=nSlices();
	for(i=1 ; i<=slices ; i++) { //function to adjust the bright field background according with the initial mean intensity (cutoff 5).
		setSlice(i);
		background = getValue("Mean");
		min = getValue("Min");
		max = getValue("Max");
		if(background<=8){
			setMinAndMax(min, 80); // for dark bright field
		}else{
			setMinAndMax(min/1.2, max);// for bright bright field
		}
		run("Apply LUT", "slice");
	}
}

The Set Measurements is only effectively used to set the number of decimals; getValue gets you a value without having to perform the actual measurement command first.

Sorry I saw it now. Thanks, the problem is that I need my images in 32 bit and apply lut does not work with 32 bit images :frowning:

Hi @mvizoso,

If you want the data range to be scaled, subtract using Process>Math>Subtract, followed by a Process>Math>Multiply to use the desired range. There are other threads in the forum that spell this out.