Image Calculator in Each File of the Directory

Hello all :slight_smile:

I am trying to write a Macro where my aim is to threshold each pictures in a file and then use image calculator to add picture 1 to picture 2; after that save this new picture (picA) and combine picA to pic3 saved as picB add to pic4 save as picC and so forth

So far I did :

macro "test" {
                run("Close All");
input = "XXX";`Preformatted text`
output = "XXX";
 
//setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++)
{
	print("current file: "+list[i]);
	if (endsWith(list[i], ".jpg"))
	{
        print("process file "+list[i]);
        action(input, output, list[i]);
	}
    else
        print("skip file "+list[i]);
}
// Operations before merging 2 pictures
function action(input, output, filename) {
	print("in action with file "+input+filename);
        open(input+filename);
        print(input + File.nameWithoutExtension);
run("8-bit");
makeRectangle(83, 7, 620, 415);
run("Crop");
run("Threshold...");
setThreshold(92, 255);
setOption("BlackBackground", false);
selectWindow("Threshold");
run("Close");
run("Gaussian Blur...", "sigma=3");
run("Threshold...");
setThreshold(65, 255);
run("Convert to Mask");
selectWindow("Threshold");
run("Close");
run("Set Scale...", "distance=446 known=21 unit=cm");

//HERE is where I need to add the image Calculator line 

run("Skeletonize");
run("Measure");
selectWindow("Results");
nameOut = File.nameWithoutExtension;
saveAs("Results", output + nameOut + ".csv");

// closes all the images
imageList = getList("image.titles");
for (i = 0; i < imageList.length; i++)
	{
		print("closing: "+imageList[i]);
	if (startsWith(imageList[i], File.nameWithoutExtension))
	{
		selectWindow(imageList[i]);
		print("closing: "+imageList[i]);
		run("Close");
	}
	}
}
}

Any guesses or information might really help me :hugs:

Thanks

Alann