Help in merging images in a macro

Hello :slight_smile:
Im currently trying to write a macro to merge channels. The images are already split, but it is difficult to merge due to the filename. Example:
Filename #1: A - 001 VW Cy5-Cy5
Filename #2: A - 001 VW FITC-FITC
Filename #3: A- 002 VW Cy5-Cy5
Filename #4: A - 002 VW FITC-FITC

My objective is to adjust brightness and contrast and merge the 001 Cy5 and FITC. Then the 002 Cy5 and FITC. The difficult part is i cannot select the name for a correct merge.

Sorry for any stupid thing that i might had said :slight_smile:

Code:

setBatchMode(true);
list = getFileList(dir1);
for (i = 0; i < list.length; i++)
	action(dir1, dir2, list[i]);

function action (dir1, dir2, filename) {
	
	run("Bio-Formats Importer", "open=[" + dir1 + filename + "] color_mode=Composite view=Hyperstack stack_order=XYCZT");
	
	selectWindow(filename + "Cy5 - Cy5");
	run("Brightness/Contrast...");
		setMinAndMax(A , B);
		call("ij.ImagePlus.setDefault16bitRange", 12);
	run("Apply LUT"); 
	
	selectWindow(filename + "FITC - FITC");
	run("Brightness/Contrast...");
		setMinAndMax(C, D);
		call("ij.ImagePlus.setDefault16bitRange", 12);
	run("Apply LUT");
	
	run("Merge Channels...", "c1=["+fullname1+"] c2=["+fullname2+"] create");
    
	run("RGB Color");
	
	saveAs("Tiff", dir2 +filename);
}

Hello @Pedro_Mateus, welcome to the forum.

It looks as if you haven’t set a few variables there.
You don’t set the fullname1 and fullname2, the dir2 isn’t set.
Or is this just an excerpt of your code?
Where/what is “the problem” you experience and what is the error message you receive?

Have you tried debugging in ImageJ1 (Plugins>New Macro, paste in your code, using Debug>Debug Macro, then use Debug>Step to execute your macro line by line while watching variable contents in the Debug variables window change according to your code)?