For loop for 1000 images

Hi everyone.
I have 1000 images and I need to run this code in Imagej for 50 times with 20 images for each.

imp = FolderOpener.open("E:\dta\original\", "");   
IJ.run(imp, "Median...", "radius=3 stack");
imp2 = imp.duplicate();
//IJ.setTool("freeline");
call("trainableSegmentation.Weka_Segmentation.loadClassifier", "E:\\dta\\classifier.model");
call("trainableSegmentation.Weka_Segmentation.getResult");
selectWindow("Classified image");
run("8-bit");
run("Invert", "stack");
run("Image Sequence... ", "format=PNG use save=[E:/dta/New folder/Classified image0000.png]");
close();
close();
selectWindow("original");
close();

I’m sorry I don’t have experience with java could you please help me?

Dear Aliarafa,
You can use the batch option (bottom close to run) in the macro or use a macro with the batch mode like this

/*
 * Macro template to process multiple images in a folder
 */

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	// Do the processing here by adding your own code.
	// Leave the print statements until things work, then remove them.
	print("Processing: " + input + File.separator + file);
	print("Saving to: " + output);
3 Likes

Ok I’ll try. Thanks a lot.