Merging images with similar prefixes together

Hi folks
still brand new to fiji macro area
would appreciate some good suggestions
My goal is to merge images with specific prefixes together (they are all under the same directory),
e.g. WTCell1_DAPI to merge with WTCell1_ER and WTCell1_actin
and i want to repeat for WTCell2
the following is my macro which i have been having some problems with quite awhile.

inputDir = getDirectory("F:/290320imaging");
outputDir = inputDir + "compilation\\";
if(!File.exists(outputDir)) File.makeDirectory(outputDir);
list = getFileList(inputDir);
DAPI= getString("F:/290320imaging","DAPI")
ER= getString("F:/290320imaging", "ER")
actin= getString("F:/290320imaging", "actin");

for(i=1; i<=list.length; i++){
ERname = inputDir + ER + i;
actinname = inputDir + actin + i;
DAPIname=inputDir + DAPI + i;

if(File.exists(actinname) && File.exists(ERname) && File.exists(DAPIname)){

// next lines are merging
run("Merge Channels...", 
"c2= ERname c3=DAPIname c6=actinname create");
saveAs("tiff", outputDir + "compiled" +T+ i);

Hi @kavator,

Welcome to the forum. We like to help. There are a few things you can do to help us help you. Some things are obvious to all of us, some are just obvious to you.

First, closing } and indentation are missing, as far as I can see. Please try to have proper indentation, as this helps all of us to combine begin and end of loops and if clauses.
Next, please try to be precise as to what problem you have for quite a while. We don’t have the files you have, so it is a bit of a guess as to what you are trying to achieve.
Can you please be a bit more specific? Then we can be more specific in our answers. Thank you !

1 Like

Hi eljonco
thank you for your suggestions!
my goal is to overlay respective channels (TIFF files) of the same sample together.
All the tiff files are within the same directory and their filenames are e.g.
WTCell1_DAPI , WTCell1_ER, WTCell1_actin, WTCell2_DAPI , WTCell2_ER, WTCell2_actin so on and so forth …
i have both WT and WTtreated cells and they have their similar respective channel tiff files as well e.g. WTtreated1_DAPI , WTtreated1_ER, WTtreated1_actin and so on …
therefore I want to specify the cells with similar prefixes to be merged together as a channel using getString() - i hope im getting this correct. pls lemme know if i misunderstand this function and it’s argument.

and during the course of merging i would also like to specify that ER is channel 2, DAPI is channel 3 and actin is channel 6

i will then save the the merged image according to it’s title
e.g. Merged_WTCell1

Hi @kavator,
In that case, I can refer to this discussion about merging four different channels. You can extend this to six and so on channels, just add more logical terms to the pattterns you see in the solutions of that discussion.

1 Like