Posted by
Olivier Burri on
Apr 29, 2016; 12:25pm
URL: http://imagej.273.s1.nabble.com/Saving-multiple-result-windows-into-the-same-excel-file-tp5016205p5016280.html
Hi all,
Regarding Fruit's macro, what Kees meant is that you do not need to save the csv file and rename the table after each run. Moreover if you have "Display Label" set in "Set measurements", you automatically get a column with the image name. Maybe it still has the extension, but you can clean that up in excel afterwards. OR you can rename your image to the name without an extension before running the analyze particles. See the augmented example below.
At the end you save this single file which has everything you need.
dir = getDirectory("path");
list = getFileList(dir);
run("Clear Results");
for (i=0; i<list.length; i++)
{
if (endsWith(list[i], ".tif"))
{
open(dir + list[i]);
name=getTitle;
IJ.renameResults(name);
name = getTitle;
dotIndex = indexOf(name, ".");
name = substring(name, 0, dotIndex);
rename(name);
run("Duplicate...", " ");
run("8-bit");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Default dark");
getThreshold(lower,upper);
setThreshold(41,255);
run("Convert to Mask");
run("Watershed");
rename(name);
run("Analyze Particles...", "size=30-Infinity display");
close();
close();
}
}
Regarding having multiple results table, you can achieve this if you really want to. It’s a bit hacky but it works quite well.
We define two functions in our macro called prepareTable and closeTable
/*
* Prepare a new table or an existing table to receive results.
*/
function prepareTable(tableName) {
updateResults();
if(isOpen("Results")) { IJ.renameResults("Results","Temp"); updateResults();}
if(isOpen(tableName)) { IJ.renameResults(tableName,"Results"); updateResults();}
}
/*
* Once we are done updating the results, close the results table
and give it its final name
*/
function closeTable(tableName) {
updateResults();
if(isOpen("Results")){ IJ.renameResults("Results",tableName); updateResults();}
if(isOpen("Temp")) { IJ.renameResults("Temp","Results"); updateResults();}
}
The way this works if you call prepareTable("My Table");
Then you can use setResult, nResults as you normally would (Because it’s called 'results')
When you are done you call closeTable("My Table"), which renames it to 'My Table' and now you can call prepareTable for a new table and so on.
You can have multiple tables open but you can only write to one at a time and switching is expensive in terms of time, in which case Kenton's suggestion is much faster.
Best
Oli
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html