Select only images of given format in folder containing other files

fiji
macro
#1

Hi again,
to add a level of complexity to my previous macro (HELP - new macro batch does not increment i), coz otherwise it is no fun, I would like to only select the image files that have a “.dv” extension in the input folder (that also contains files with .log, .tif, .png) to process with my macro.

I managed to get a mini scrip taht counts the number of files with the given format .dv (trolling through the archives), but unsure how I can restrict my loop to files with .dv …
I know it has to be an if loop that has an argument on the strings of the file names but not sur how to write it…
Thanks in advance

Debbi

ImgNumber=0;
ImgFormat= ".dv";
//open directory of images
Dialog.create("Batch Processing - RAW to WF OTF");
	Dialog.addCheckbox("Use Bio-Formats Importer ", true);
	Dialog.addString("Image Format:", ImgFormat);
	Dialog.show();
ImgFormat= Dialog.getString();
Bio=Dialog.getCheckbox();

//select location where images are stored
input = getDirectory("location where images are stored");
output = getDirectory("Location for results");

// determine number of Files of given FileFormat ("ImgNumber")
list = getFileList(input);
   for (im=0; im<list.length; im++)
    if (endsWith(list[im], ImgFormat)) 
        ImgNumber = ImgNumber+1;


setBatchMode(false);

//loop to sequentially open images
for (i=0; i<ImgNumber; i=i+1){{
full = input+list[i];
print(full);
// LIMIT the opening of file and conversion to WF to files with the ".dv" format

		if (Bio==true){
		run("Bio-Formats Importer", "open=full autoscale color_mode=Composite view=Hyperstack stack_order=XYCZT");
				} 
		else {
		open(full);
		}

//Get the name without the extension
filename=getTitle();
ShortFileName=substring(filename, 0, lastIndexOf(filename,"."));
//rename
rename("RAW");
// process
selectWindow("RAW");
run("Raw SI Data to Pseudo-Widefield", "angles=1 phases=5 intensity rescale");
rename("WF_temp");
}
// save
selectWindow("WF_temp");
rename(ShortFileName+"_RIN_PWF");
print(ShortFileName+"_RIN_PWF" + " done");
outWF = output + ShortFileName + "_RIN_PWF ";
saveAs("tiff", outWF);
run("Close All");
ImgNumber=ImgNumber+1;
}
setBatchMode(false);

print("All done - " + ImgNumber + " images processed");
#2

solved … added

if (endsWith(list[i], ".dv"))

to my for loop (whole macro below)

ImgNumber=0;
ImgFormat= ".dv";
//open directory of images
Dialog.create("Batch Processing - RAW to WF OTF");
	Dialog.addCheckbox("Use Bio-Formats Importer ", true);
	Dialog.addString("Image Format:", ImgFormat);
	Dialog.show();
ImgFormat= Dialog.getString();
Bio=Dialog.getCheckbox();
		
//select location where images are stored
input = getDirectory("location where images are stored");
output = getDirectory("Location for results");


// determine number of Files of given FileFormat ("ImgNumber")
list = getFileList(input);
  // for (im=0; im<list.length; im++)
   // if (endsWith(list[im], ImgFormat)) 
     //   ImgNumber = ImgNumber+1;
        
setBatchMode(false);
//loop to sequentially open images
for (i=0; i<list.length; i=i+1)
{
	{
		// LIMIT the opening of file and conversion to WF to files with the ".dv" format
	 if (endsWith(list[i], ".dv")) 
	 	{
	 	ImgNumber=ImgNumber+1;
full = input+list[i];
print(full);

		if (Bio==true){
		run("Bio-Formats Importer", "open=full autoscale color_mode=Composite view=Hyperstack stack_order=XYCZT");
				} 
		else {
		open(full);
		}

//Get the name without the extension
filename=getTitle();
ShortFileName=substring(filename, 0, lastIndexOf(filename,"."));
//rename
rename("RAW");
// process
selectWindow("RAW");
run("Raw SI Data to Pseudo-Widefield", "angles=1 phases=5 intensity rescale");
rename("WF_temp");

// save

selectWindow("WF_temp");
rename(ShortFileName+"_RIN_PWF");
print(ShortFileName+"_RIN_PWF" + " done");
outWF = output + ShortFileName + "_RIN_PWF ";
saveAs("tiff", outWF);


run("Close All");
		}
	}
}

setBatchMode(false);
print("All done - " + ImgNumber + " images processed");

#3

Hi @Debora_KellerOlivier,

great that you solved your issue yourself!

Please note that the Process_Folder.ijm template macro (available within the script editor via Templates > ImageJ 1.x > Batch > Process Folder) contains an example of filtering for file extensions: