How to get max value of stack using macro?

stack
macro
Tags: #<Tag:0x00007fd541cef5e0> #<Tag:0x00007fd541cef478>

#1

Hi, I’m a complete novice with using macros for ImageJ so bear with me.
I’m trying to divide a stack with z-slices with the max value of the stack using macro. I can get the value by going to Histogram with Stack histogram ticked. But the macro I wrote only gave the max value for the first slice of the stack.

The macro I have so far:

selectWindow(redTitle);
Stack.getDimensions(width,height,channels,slices,frames);
for (j=1;j<slices+1;j++){
Stack.setSlice(j);
getStatistics(area, max);
maxred = max;

}
selectWindow(redTitle);
run(“Divide…”, “value=maxred”);


#2

Hello,

In your case I will use the “Z project” method to get maximum of each pixel of each slice in a single image then you get the max of this image.

If it helps you…


#3

Hi @dentedaura,

you can also use

Stack.getStatistics(voxelCount, mean, min, max, stdDev);

to get the maximum value of the stack.


#4

Thanks! This works perfectly.