Macro for computing histogram of a stack

Hi @CellKai

I am trying to edit your concise macro to also work for image stacks that contain both negative and positive density values, while maintaining a bin width of 1 (i.e. Number of bins = max + |min|)

I have tried the following code, but am getting errors about the brackets - can you see what I am doing wrong?

Stack.getStatistics(voxelCount, mean, min, max, stdDev);
run("Histogram", "bins="+max+ - +min+" x_min="+min+" x_max="+max+" stack");

Many thanks.

Hi Rachel,
could you try like this and see if it works for you:

Stack.getStatistics(voxelCount, mean, min, max, stdDev);
nBins = max + abs(min);
run("Histogram", "bins="+nBins+" x_min="+min+" x_max="+max+" stack");

if you want further information, there is a nice guide as introduction to macro programming and a handy references for the available macro functions .
Make sure to check out the macro recorder function with awesome tab-autocomplete!

2 Likes