How to make a montage of all the opened images and assign colors to different channels?

I’d like to write a Macro script for making montages of images. I have 2 questions.

I’ll either have 2 or 3 czi image files opened. I’d like to combine these images horizontally and save it as 1 big montage file. I have individual script but I don’t know how to make it cohesive and dynamic, so that it could accommodate for different number of opened image files.

Also after I have a montage, I’d like to change all the channels into grey scale. This is to see their brightness. Then I’d like to have a script separately that could assign green to channel 1, blue to channel 2 (DAPI), red to channel 3.

image_name = getTitle; 
rename("SF"); // 1st file

image_name = getTitle;  // don't know how to pick the 2nd file, instead of "SF"
rename("CR"); // 2nd file

run("Combine...", "stack1=SF stack2=CR"); // 1st combine

image_name = getTitle;  // don't know how to pick the 3rd file, instead of "Combined Stacks"
close(Combined Stacks);
rename("KD"); // 3rd file

run("Combine...", "stack1=[Combined Stacks] stack2=KD"); // 2nd combine

run("Grays"); // each images have 3 channels, I want to see all of them in grayscale first, then assign colors to each channel accordingly

Thank you for your time.

Hi @CeC,

Theyre is a few mistakes in your code.
getTitle will return the name of the active image. So you can use it this way to select your images (btw, prefer selectImage instead of selectWindow, because the later doesn’t work in batch mode).
In you code, after selecting your image, you close it, so when you rename, it will rename the next image. So it won’t work.
You have to find a way to “guess” the name of the images you want to select. For example if you know that you have a sample name and 2 acquisitions, you can guess that your images will be named SampleXXX_chanel1 and SampleXXX_chanel2…



Thank you for your reply! For finding the substring, the following renaming scheme seemed to work.

How can this code be reiterated for all of opened/active images other than clicking manually?

lookFor1 = "SF";
lookFor2 = "CR";
lookFor3 = "KD";

if (indexOf(image_name, lookFor1) >= 0) { // find substring -> rename
else (indexOf(image_name, lookFor2) >= 0) { // find substring -> rename
else (indexOf(image_name, lookFor3) >= 0) { // find substring -> rename

run("Combine...", "stack1=SF stack2=CR"); // 1st combine
run("Combine...", "stack1=[Combined Stacks] stack2=KD"); // 2nd combine

Thank you.

You could use getList(“image.titles”) that gives you the title of all opened window images


Thank you! I now have a script for quick montage.

Do you know why when I make the montage, the image colors change? For example, channel 2 should be blue (DAPI) but it’s green when I run the code.