How to automatically define split channels for creating concatenated stacks in a macro

Hi everybody,
I need help with a small macro I want to create. Background: I have ics2-format stacks from my deconvolution program and I need them for an IDL based programm as tiff and in an concatenated stack order. Since I have tons of these stacks I hoped to get my macro running to convert these files without any further questions.
Now I have two problems:
First: How to automatically define the split channels for creating concatenated stacks the macro. After splitting the stack to channel stacks ImageJ names them C1-…, C2-…and so on + filename. Since the file name differs in some parts I can not just use this as source. Now I tried several stuff that imageJ just takes the image containing “C1” as image 1, “C2” as image 2 and so on. Until now none of my tries were accepted :cry:

Here is my current draft…

run("Bio-Formats", "open autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
dir = getDirectory("image");
  name=getTitle;
  path = dir+name;
run("Split Channels");
run("Concatenate...", "  title=[Concatenated Stacks] image1=[name, "C1"] image2=[C2.ics] image3=[C3.ics] image4=[-- None --]");
saveAs("Tiff", path);
close();

Another question I have is how I can put this in a loop. For images just “opened” it always worked with “openNext” but with the bioformats-importer this is also an issue.

Would be great if you could help me!
Cheers,
Anja

you can make a list to iterate over different files and run your program. Use getFileList(directory) to create a list. And use this list in your BioFormats import macro code

For the names issue. My ImageJ adds (blue), (green) and (blue) at the end of the image. So this is how I handle it.

a = getTitle();
run(“Split Channels”);
selectWindow(a+" (red)");
close();
selectWindow(a+" (green)");
close();
selectWindow(a+" (blue)");
close();

As I understand from your case ImageJ adds “C1-” at the front of the imagename. That means that you should run this code.

run("Bio-Formats", "open autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack > stack_order=XYCZT");
dir = getDirectory();
name=getTitle;
C1 = "C1-"+name;
C2 = "C2-"+name;
C3 = "C3-"+name;
run("Split Channels");
run("Concatenate...", "  title=[Concatenated Stacks] image1=[C1] image2=[C2] image3=[C3] image4=[-- None --]");
saveAs("Tiff", dir+name);
close();

Hope this helps you out.

Hi,

So that I understand more clearly what you want:

You have a 3d mutlichannel image that has the order C1Z1 C2Z1 C1Z2 C2Z2 … C1Zn C2Zn
and you would like it to be C1Z1 C1Z2 … C1Zn C2Z1 C2Z2 … C2Zn

Instead of playing with splits and recombines, could I offer the following solution with an example:

First, change the order of Z and C using “Re-Order Hyperstack”, then use “Hyperstack to Stack”

run("Confocal Series (2.2MB)");
run("Re-order Hyperstack ...", "channels=[Channels (c)] slices=[Slices (z)] frames=[Frames (t)]");
run("Hyperstack to Stack");
rename("New Order");


run("Confocal Series (2.2MB)");
run("Hyperstack to Stack");
rename("Original Order");

To run this on a folder You can run this using Process > Batch > Macro…, and pasting those two lines there, defining your start and end folders and you are good to go.

No variables to play with, no hassle. Hope this helps

1 Like

Dear all,
thanks a lot!! Both variants are working fine.
Best regards,
Anja