Conditionnal Merge

fiji

#1

Hi Everyone,

i am trying to develop a macro to treat different raw pictures from a High Content screening machine.
I reached to do a lot of things (open a diag box at start to ask for the name of the labelling on each channel, the color the user want as a LUT for each channel also, an optional function to correct Brightness and Contrast, and a check box on each channel to ask the macro for a merge with each of the channel where that box is checked). All that work well, but I have difficulties to get the merge thing workinf correctly.
the thing is that channels can be from 1 or 2 up to 5 different channels. Secondly, the user can choose to affect different colors to each channel (from blue, red, green, magenta and yellow). So the merge process should deal with a variable number of channels, and the colors could not be always associated with the same channel. What is a problem to me when i try to put it on the “merge” code which is kind of:
run(“Merge Channels…”, “c1=”+Chan1+" c2="+Chan2+" c3="+Chan3+" c6="+Chan6+" c7="+Chan7+" create");

the thing I try to elaborate could be something like:
if Channel1 merge is checked and Channel2 merge is checked, and… etc with a variable number of channels, do a merge with the appropriate number of chanel.
That is a first problem to me, but the second one is how to get the chanel with the appropriate color into the correct “Merge” Channel C1 or C2 or…etc…

here is a short part of the code, with just the diag box with the options porposed to the user, and the conditional part to open the pictures where the optional Merge checkbox is checked. The question is how to merge the pictures then…

thank you


// demande du chemin du dossier dans lequel sont les images à convertir en jpeg
analy=getDirectory("choisir le dossier où sont localisées les images à convertir");
//evaluation du nombre d'images dans le dossier
analyList=getFileList(analy);

 
 // créé une boite de dialogue 
 title = "Untitled";
  width=512; height=512;
  Dialog.create("New Image");
 Dialog.addChoice("Type:", newArray("jpg","Tiff", "Bmp")); //choix du format d'enregistrement
 Dialog.addChoice("Ch1_Color:", newArray("Blue","Red","Green","Yellow","Magenta")); // choix de la couleur du canal 1
 Dialog.addString("Marquage Canal 1:", "marquage");
 Dialog.addCheckbox("Ch1 Merge?", false);
 Dialog.addChoice("Ch2_Color:", newArray("Green","Blue","Red","Yellow","Magenta")); // choix de la couleur du canal 2
 Dialog.addString("Marquage Canal 2:", "marquage");
 Dialog.addCheckbox("Ch2 Merge?", false);
 Dialog.addChoice("Ch3_Color:", newArray("Red","Blue","Green","Yellow","Magenta"));  // choix de la couleur du canal3
 Dialog.addString("Marquage Canal 3:", "marquage");
 Dialog.addCheckbox("Ch3 Merge?", false);
 Dialog.addChoice("Ch4_Color:", newArray("Yellow","Green","Blue","Red","Magenta")); // choix de la couleur du canal 4
 Dialog.addString("Marquage Canal 4:", "marquage");
 Dialog.addCheckbox("Ch4 Merge?", false);
 Dialog.addChoice("Ch5_Color:", newArray("Magenta","Red","Blue","Green","Yellow"));  // choix de la couleur du canal5
 Dialog.addString("Marquage Canal 5:", "marquage");
 Dialog.addCheckbox("Ch5 Merge?", false);
 Dialog.addCheckbox("Correction", false); // correction luminosité contraste?
   
Dialog.show();
type = Dialog.getChoice();
Ch1_Color=Dialog.getChoice();
title1=Dialog.getString();
ch1Merge = Dialog.getCheckbox();
Ch2_Color=Dialog.getChoice();
title2=Dialog.getString();
ch2Merge = Dialog.getCheckbox();
Ch3_Color=Dialog.getChoice();
title3=Dialog.getString();
ch3Merge = Dialog.getCheckbox();
Ch4_Color=Dialog.getChoice();
title4=Dialog.getString();
ch4Merge = Dialog.getCheckbox();
Ch5_Color=Dialog.getChoice();
title5=Dialog.getString();
ch5Merge = Dialog.getCheckbox();
Correction = Dialog.getCheckbox();

merg();




function merg (){

	for (l=0; l<analyList.length; l++){
		
		if(endsWith(analyList[l], "/")){   // if the name is a subfolder... 
		 	rec = analy + analyList[l]; 
		 	//recuperation de la liste des images ou sous dossier dans le Dossier Rec
         	list = getFileList(rec);

					for(k=0;k<list.length;k++){
						if(endsWith(list[k], "/")){   // if the name is a subfolder... 
					 		rec2 = rec+list[k]; 
					 		//recuperation de la liste des images ou sous dossier dans le Dossier Rec
			         		list2 = getFileList(rec2);
			
         	                  		

									// boucle d'ouverture de des images de chaque sous dossier tour par tour
									for (p=0;p<list2.length;p++){
										if (ch1Merge==true){
											if(endsWith(list2[p],"."+type)&&indexOf(list2[p],title1)>=0){
											open(rec2+list2[p]);
											rename("1");
										}}
										if (ch2Merge==true){
											if(endsWith(list2[p],"."+type)&&indexOf(list2[p],title2)>=0){
											open(rec2+list2[p]);
											rename("2");
										}}
										if (ch3Merge==true){
											if(endsWith(list2[p],"."+type)&&indexOf(list2[p],title3)>=0){
											open(rec2+list2[p]);
											rename("3");
										}}
										if (ch4Merge==true){
											if(endsWith(list2[p],"."+type)&&indexOf(list2[p],title4)>=0){
											open(rec2+list2[p]);
											rename("4");
										}}
										if (ch5Merge==true){
											if(endsWith(list2[p],"."+type)&&indexOf(list2[p],title5)>=0){
											open(rec2+list2[p]);
											rename("5");
										}}
										run("Merge Channels...", "c1=[A01f00 Ki67.jpg] c2=[A01f00 CTIP2.jpg] c3=[A01f00 DAPI.jpg] c6=[A01f00 DAPI.jpg] c7=[A01f00 DAPI.jpg] create");
        							} 
						}
					}
										
		}
	}
}