ROI manager data exported as a .xls file from a directory batch processing

Dear Forum users,

I’m relatively new to ImageJ, but I have encountered a problem that is not yet solved on this forum.
What I’m trying to do is the following:

There are regions on the images I want to process which are more fluorescent than others (black+white). All images are in .png. What I’m trying to do, is to manually adjust the threshold of the image, create a selection around the fluorescent spots, split the selection in the ROI manager, measure the selection and export these measurements to an excel file. This works for me, but just on 1 image. Now I’ve tried to get this to work on a batch, but this is too hard for me. I’ve tried using exact template given in the Fiji batch processing template. Could someone help me?

Kind Regards,
Jan Jaap Burggraaf
The Netherlands

Below the code I use:

input = getDirectory("Input Directory");
output = getDirectory("Output Directory");

Dialog.create("File type");
Dialog.addString("File suffix: ", ".xls", 5);
Dialog.show();
suffix = Dialog.getString();

processFolder(input);

function processFolder(input) {
	list = getFileList(input);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + list[i]))
			processFolder("" + input + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	run("Threshold...");
setAutoThreshold("Huang dark");
setThreshold(6972, 13988);

run("Create Selection");

run("ROI Manager...");
roiManager("Split");

run("Select All");
roiManager("Measure");

saveAs ("M:\\2b. Clinical results\\SNR vs TBR\\Signal-to-Noise Ratio\\Resultaten Muizen N1\\)

}

Hi

to me there are several issues with your macro:

is this for input or output?

you have three input arguments, but not one of the is used in the function.
I guess the first line should be something like:

open(input + file);

For a start there is a quote missing.
Also in case you want to have one file per input image you would need to generate an output file name. Something like:

saveAs(output + substring(name, 0, lengthOf(name)-3 + xls);

otherwise the same file will be overwritten each time the function is called.

Hope that helps,

Felix

1 Like

Thank Felix!

As I’m still learning, it helped me a great deal! I think I have improved my macro a lot in a short period of time!
Thanks a lot! Now I have a new problem, and I’ve posted it on the forum again. Hope you can maybe help.

Jan Jaap