Results Table Analysis

Hi everyone,
I´m trying to extract values from the results table and save them automatically to a .txt file, however I´m a little stuck now.

I´m using the “Analyze Particles” command to get the results table and would like to get a sum of all the “Area” values.

for example in this case I´d like to get only the value 74 saved to my log file
Results

Does anyone know a way to do that?

Thanks a lot!

1 Like

Hi @v.82588,

there are methods for reading / writing tables: getResult and setResult. You can see them and read their documentation by typing “Result” in Fijis script editor:

The saveAs method allows you to save a table to disc.

Furthermore, feel free to read a bit more about working with tables on slides 12-17 here:

I hope that helps!

Cheers,
Robert

1 Like

Thank you very much for the quick reply, the Powerpoint is very informative!

However it does not completely solve my problem.

I was looking for a way to automatically create a sum of values from the results table within Fiji.

I am analyzing 100+ images in different selections, therefore only saving the results table is a little impractical.

My goal is to append the sum value to a txt file for each selection to create only one file for each selection.

Appending the value to the file already works, my only problem is creating a sum from the results.

Hey @v.82588,

then you may want to give Table.getColumn and Array.getStatistics a try :wink:

I hope that helps.

Cheers,
Robert

1 Like

Thanks for the tip!
I was able to more or less solve the problem with the Table.getColumn command.
This is my solution, maybe it helps somebody with a similar problem:

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

processFolder(input);

function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	run("ROI Manager...");
	roiManager("Open", "C:/Users/...../4.roi"); //insert your path here if you have a custom selection
		
	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) {
	open(input + File.separator + file); 
	run("Auto Local Threshold", "method=Phansalkar radius=15 parameter_1=0 parameter_2=0 white");
	roiManager("Select", 0);
	run("Invert");
	run("Invert");
	run("Analyze Particles...", "size=16-Infinity display clear");
	run("Set Measurements...", "area sum redirect=None decimal=3");
	x = Table.getColumn("Area");
	Array.print(x);
	close();
}

It isn’t the most elegant way, after the analysis I have to save the log file manually and perform the sum calculation in excel, however it works.
If someone has a better solution please feel free to add it here!

Cheers

Ps: you might wonder why I have a run("Invert") command twice in there…
I am not sure why but for some reason the analyze particles command doesn’t work properly without it, and this was a simple work around. Maybe one of you knows the reason for it.

1 Like