Maximum projection of one channel and merge to zstack

Hello everyone,

New in the forum and i hope I reach someone with more experience than me here.
What I have is an enormous folder with hyperstacks made of 4 channels with variable number of slices (single frames). What I need is to separate one of the channels (my selection marker) and run a maximum projection over it. Until here I’m good with the process in batch. What I want to do it to duplicate that MAX-projected image and re-concatenate it to match the specific number of slices that the original image had. That way I can re-merge it as an hyperstack with the other 3 channels.

Since my images do not have the same number of slices, I cannot define a specific number in my macro. Instead, I think I have to count the number of slices of each image so I get an “n” to later duplicate&concatenate that same number of Maximum projection images. But I dont know how to do this!

If I can get help to write this instructions in a macro in batch (PLEASE help me!!), I’m ready to run further macros to define ROIs and measure the MFI of independent channels in single planes.

I hope I didn’t make it too confusing and I’m eager to hear back


Hi @CarolinaR,

Let me see if I understand correctly your (single stack) goal: you want to replace one of the channels of the hiperstack with the MIP of that channel repeated for each z. Right?

If that’s the case, it should be pretty straightforward:



Stack.getDimensions(width, height, channels, slices, frames); // <<< the info you wanted about the stack

run("Split Channels");
selectWindow("C" + maxChannel + "-" + title);
run("Z Project...", "projection=[Max Intensity]");
selectWindow("MAX_C" + maxChannel + "-" + title);

selectWindow("C" + maxChannel + "-" + title);
for (i = 0; i < slices; i++) {
run("Select None");

chan_string ="";
for (i = 0; i < channels; i++){
	chan_string += "c" + (i + 1) + "=[C" + (i + 1) + "-" + title+"] ";

run("Merge Channels...", chan_string + " create");

rename("Max_C" + maxChannel + "-" + title);

Does this work for you? If so, it can be easily run in batch.