Stack to Hyperstack: calculate slices from channels/slices/frames combination

Hi all,

I was wondering if it is possible to - in a macro - automatically calculate the number of slices I need for “Stack to Hyperstack” transformations by using a function like (total number of slices)/number of channels (the number of frames is not important, as it is always 1. However, the total number of slices differs for the different stacks). As an example: stack has 3 channels and a total of 153 slices and 1 frame (timepoint). A transformation to a Hyperstack would thus consist of: 3 channels + 51 slices + 1 frame. Is it possible to calculate the 51 slices as indicated above? I would like to transform the stacks with a macro, without the need to enter everything again and again.

I hope you get my problem and can help me out!

Best wishes,

Do you mean something along these lines?

// @int nChannels (label="How many channels?")

newNSlices = nSlices / nChannels;

print ("Converting to " + nChannels + " channels and " + newNSlices + " slices (and 1 frame)")
run("Stack to Hyperstack...", "order=xyczt(default) channels=" + nChannels + " slices=" + newNSlices + " frames=1 display=Color");

That’s the spirit! Great, thanks a lot!

Is there also a possibility to call for the # of channels without the need to enter it manually?
Basically, just as the nSlices call for the number of slices

Thanks again!