# Maximum intensity Z-project alters values randomly

I have a video, containing 12 z images, for 40 time points. Now, to correct for z-drift I want to select the brightest image at every time point, and I do this by selecting Z-project > maximum projection. I had always assumed that it would simply take the z image with the corresponding highest mean value…

However, by doing the analysis manually, not only did I find that Z-projected the values are different from the original, they’re also randomly different.

I have plotted the results. As you can see, this can easily lead to false interpretation of data when you trust the software to be objective. Am I doing something wrong, or is this feature broken? I have not messed with image type, colors, thresholds, brightness or anything. Images are as vanilla as can be.

Hi @komodovaran,

Here the definition from the IJ user guide

Maximum Intensity Projection (MIP) creates an output image each of whose pixels contains the maximum value over all images in the stack at the particular pixel location.

The assumption that the method picks the brightest slide is incorrect. As the name tells you, it is a projection which means that it projects all the information from a stack into a single image. Thus, the result is a combination of information from all slices not a particular slice.
This is also true for all the other methods you can choose in the Z-project function.

The following macro selects the brightest slice in your stack:

``````brightestMean = 0;
brightestSlice = 1;
for(i=1; i<nSlices; i++) {
setSlice(i);
getStatistics(area, mean);
if(brightestMean<mean) {
brightestMean = mean;
brightestSlice = i;
}
}
setSlice(brightestSlice);

``````
3 Likes

Thank you so much! I always thought it simply took the brightest image, as the projection in almost any case (well, except now ) looked like the brightest image out of a stack.

The macro only sets one image as the brightest. What I want to do is finding the brightest z (out of 12) for every t (40 timepoints in total), and putting them into a new timelapse, with only a single image for every timepoint.

This might be the solution to get the brightest slice in a z-t-hyperstack:

``````
setPasteMode("Copy");
originalImage = getTitle();

getDimensions(width, height, channels, slices, frames);
newImage(originalImage + "_brightest slice", bitDepth+"-bit", width, height, frames);
brightestSliceTimeSeries = getTitle();

for(t=1; t<=frames; t++) {
selectWindow(originalImage);
Stack.setFrame(t);
brightestMean = 0;
brightestSlice = 1;
for(i=1; i<slices; i++) {
Stack.setSlice(i);
getStatistics(area, mean);
if(brightestMean<mean) {
brightestMean = mean;
brightestSlice = i;
}
}
//print(brightestSlice); //test
Stack.setSlice(brightestSlice);
run("Select All");
run("Copy");
selectWindow(brightestSliceTimeSeries);
Stack.setSlice(t);
run("Paste");
}
``````
1 Like

It looks like it’s picking out the brightest images, but the stack it’s pasting into is just 40 frames with 0 values.

Hi @komodovaran,

if you can provide a part of your stack, i can test it. might be a problem of different bit-depth or selections etc.

You can run a test on the the ImageJ sample image “Mitosis” (File►Open Sample►Mitosis)

You know what? I might just have clicked something wrong. It certainly works now on the exact same sample.

Thanks a lot!