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 ="E:\dta\original\", "");, "Median...", "radius=3 stack");
imp2 = imp.duplicate();
call("trainableSegmentation.Weka_Segmentation.loadClassifier", "E:\\dta\\classifier.model");
selectWindow("Classified image");
run("Invert", "stack");
run("Image Sequence... ", "format=PNG use save=[E:/dta/New folder/Classified image0000.png]");

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 for a version of this code
// in the Python scripting language.


// 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);

Ok I’ll try. Thanks a lot.