 # Min max from List.setMeasurements after Z-project != Stack.getStatistics

In order to convert a series of 16-bit images to 8-bit, but to keep the relative intensities for all images in a folder the same, I try to find the minimum and maximum pixel value. I found three ways to obtain these values. Worryingly, max Z projection is giving consistently a different lower value.
Below is a synthetic example that consistently (in 3 runs) gives me a different value for the min in the stack, for my real data set I have the same problem.
Which method am I using in a wrong way?

``````close("*");
newImage("testminmax", "16-bit random", 2048, 2048, 40);
run("Divide...", "value=4 stack");
Stack.getStatistics(voxelCount, mean, smin, smax, stdDev);
mmin=65536;mmax=0;
for(slice=0;slice<nSlices();slice++){
setSlice(slice+1);
List.setMeasurements();
min=List.getValue("Min");
max=List.getValue("Max");
if (min<mmin){mmin=min;minslice=slice;}
if(max>mmax){mmax=max;maxslice=slice;}
}
run("Z Project...", "projection=[Max Intensity]");
List.setMeasurements();
pmin=List.getValue("Min");
pmax=List.getValue("Max");
print (smin+" "+smax+" "+mmin+" "+mmax+" "+pmin+" "+pmax);
``````

When projecting along z, you keep the maximum at every x,y position. The minimum of the resulting image is expected to be greater (or equal) to the minimum of the stack.

You should do Min Intensity projection in order to preserve the minimum value in your image.

(Slap forehead) Obvious. And I should do two projections, one for min intensity (and obtain the min from it), and one for max intensity (and obtain the max for it).
Which makes the method using two projections (from a virtual stack) slower than the Stack.getStatistics or the manual routine. All was a result of timing the various methods, after a huge stack appeared to be very slowly processed.

Big thanks.