Batch script using Template matching plugins

Hi all,
I’m using ImageJ 1.52 a (Java 1.8.0_172). I’m a newbie having difficulty figuring out Java language. I’m trying to perform matching to cut out individual well images from a 96 well plate. To do that, I have a template folder containing 48 individual wells, and need to match all these wells to a full 96-well image. The plugins I use is Template matching available at https://sites.google.com/site/qingzongtseng/template-matching-ij-plugin . I have written the code below but encountered an error:

Undefined variable in line 8: open (dir1 + <list> [i]);

The code:

dir1=getDirectory("Choose the plates folder");
list1=getFileList(dir1); 
dir2=getDirectory("Choose the templates folder");
list2=getFileList(dir2);
dir3=getDirectory("Choose output directory");
setBatchMode(true); //open images one by one instead of all at once;
for(i=0; i<list1.length; i++) {
	open(dir1+list[i]);
	imageTitle1=getTitle();
	for(j=0; j<list2.length; j++) {
		open(dir2+list[j]);
		imageTitle2=getTitle();
		run("cvMatch_Template...", "image=imageTitle1 method=[Normalized cross correlation] template=imageTitle2 tolerence=0.10 threshold=0");
		run("Duplicate...", " ");
	saveAs("Tiff", dir3 + list[j]); }
		}
	while(nImages > 0) close();
	setBatchMode(false);
close();

Thank you very much.

Hi Truc,

Welcome to the forum!

The “<>” around list in your error indicates that it can’t find something called “list”. Prior to that, you name your lists either “list1” or “list2” so it’s not surprising that it can’t find one without a number.

Try replacing your line 8 with:

open(dir1+list1[i])

And line 10 with:

open(dir2+list2[j]);

Good luck!

1 Like