Merge channels from one folder containing all images as separate channels

I have a list of images separated by name and channels (3) and im trying to merge images in groups of 3 and save as composites according to the name identifier. The structure is “image1_ch1”, “image1_ch2”, “image2_ch3”; “image2_ch1”, “image2_ch2”…and so on.
We tried using substrings but only works with the first set of 3 images in the folder using:

subname=substring(name, 0, 8);
run("Merge Channels...", "c1=["+subname+"_ch3.tif] c2=["+subname+"_ch1.tif] c3=["+subname+"_ch2.tif] create keep");

We dont have experience yet with arrays and loops, etc.

Any help?



Loops will definitely do the trick in this case… so something like:

#@File(label = "Input directory", style = "directory") input
listImages = getFileList(input);
numImages = listImages / 3;  //assuming it is divisible by 3 in all cases... 

subname=substring(name, 0, 7);
for (i = 1; i < numImages+1; i++) {
     run("Merge Channels…", "c1=["+subname+i+"_ch3.tif] c2=["+subname+i+"_ch1.tif] c3["+subname+i+"_ch2.tif] create keep");

I have not tested this code - so might still need some tweaking on your end… but to get you started on Scripting in ImageJ - here are some helpful links:

Too - looks like with your naming scheme… you are also dealing with stacks… no? You might want to read over the Importing Image Files page of the ImageJ wiki - you might not even need to script this!

eta :slight_smile:

1 Like