Hi everyone,
I've been using a simple macro I wrote in order to analyze particles from .tif files. The problem is that I would like to have the results be exported automatically to the same excel file, with each different result windows being indicated there (so as to tell which results are from which image). This is the macro I have for now, any help would me much appreciated dir = getDirectory("path"); list = getFileList(dir); for (i=0; i<list.length; i++) { if (endsWith(list[i], ".tif")) { open(dir + list[i]); 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"); run("Analyze Particles...", "size=30-Infinity show=Nothing display clear include"); close(); name=getTitle; IJ.renameResults(name); close(); } } Cheers |
Hi,
Not totally sure I understand what you try to do you but if you take out the "clear" option in run("Analyze Particles...", "size=30-Infinity show=Nothing display clear include"); you will get a single results file with all your data and with a label indicating from which image the results are. Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Fruits Sent: 21 April 2016 09:07 To: [hidden email] Subject: Saving multiple result windows into the same excel file Hi everyone, I've been using a simple macro I wrote in order to analyze particles from .tif files. The problem is that I would like to have the results be exported automatically to the same excel file, with each different result windows being indicated there (so as to tell which results are from which image). This is the macro I have for now, any help would me much appreciated dir = getDirectory("path"); list = getFileList(dir); for (i=0; i<list.length; i++) { if (endsWith(list[i], ".tif")) { open(dir + list[i]); 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"); run("Analyze Particles...", "size=30-Infinity show=Nothing display clear include"); close(); name=getTitle; IJ.renameResults(name); close(); } } Cheers -- View this message in context: http://imagej.1557.x6.nabble.com/Saving-multiple-result-windows-into-the-same-excel-file-tp5016205.html Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
This post was updated on .
Hi, thanks for the advice! But still, this does not solve my problem, I can create an excel file for each image, but I would like a single file with all data within. The macro is like this right now:
dir = getDirectory("path"); list = getFileList(dir); for (i=0; i<list.length; i++) { if (endsWith(list[i], ".tif")) { open(dir + list[i]); 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"); run("Analyze Particles...", "size=30-Infinity display"); name=getTitle; IJ.renameResults(name); dotIndex = indexOf(name, "."); name = substring(name, 0, dotIndex); saveAs("Results", dir + name + ".csv"); close(); close(); } } Any other mistake I am making or any idea to make the results get compiled properly? |
Fruits,
See the example here: http://imagej.1557.x6.nabble.com/How-to-create-a-customised-results-table-and-add-data-to-it-within-a-macro-td5000701.html Create a custom results table above your image loop. Print results and "name" to custom results table from each image in the loop. Save out results file after all loops are done. B On Thu, Apr 21, 2016 at 12:39 Fruits <[hidden email]> wrote: > Hi, thanks for the advice! But still, this does not solve my problem, I can > create an excel file for each image, but I would like a single file with > all > data within. The macro is like this right now: > > dir = getDirectory("path"); > list = getFileList(dir); > > for (i=0; i<list.length; i++) > { > if (endsWith(list[i], ".tif")) > { > open(dir + list[i]); > 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"); > run("Analyze Particles...", "size=30-Infinity display"); > name=getTitle; > IJ.renameResults(name); > name = getTitle; > dotIndex = indexOf(name, "."); > name = substring(name, 0, dotIndex); > saveAs("Results", dir + name + ".csv"); > close(); > close(); > } > } > > > Any other mistake I am making or any idea to make the results get compiled > properly? > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/Saving-multiple-result-windows-into-the-same-excel-file-tp5016205p5016208.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
If you have a folder of many results (say from different days) tables you
can import one results table at a time (in a loop) and add the data via a getResult("Column",row) loop to a few Arrays and then print the Arrays to a new data table. Repeat for all the files to same table. Nb you can not have two 'results' tables open at the same time. You need to make a 'text' based table like the link in the last mail. Kenton On 21 Apr 2016 13:36, "Brandon Hurr" <[hidden email]> wrote: > Fruits, > > See the example here: > > http://imagej.1557.x6.nabble.com/How-to-create-a-customised-results-table-and-add-data-to-it-within-a-macro-td5000701.html > > Create a custom results table above your image loop. > Print results and "name" to custom results table from each image in the > loop. > Save out results file after all loops are done. > > B > > > On Thu, Apr 21, 2016 at 12:39 Fruits <[hidden email]> wrote: > > > Hi, thanks for the advice! But still, this does not solve my problem, I > can > > create an excel file for each image, but I would like a single file with > > all > > data within. The macro is like this right now: > > > > dir = getDirectory("path"); > > list = getFileList(dir); > > > > for (i=0; i<list.length; i++) > > { > > if (endsWith(list[i], ".tif")) > > { > > open(dir + list[i]); > > 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"); > > run("Analyze Particles...", "size=30-Infinity display"); > > name=getTitle; > > IJ.renameResults(name); > > name = getTitle; > > dotIndex = indexOf(name, "."); > > name = substring(name, 0, dotIndex); > > saveAs("Results", dir + name + ".csv"); > > close(); > > close(); > > } > > } > > > > > > Any other mistake I am making or any idea to make the results get > compiled > > properly? > > > > > > > > -- > > View this message in context: > > > http://imagej.1557.x6.nabble.com/Saving-multiple-result-windows-into-the-same-excel-file-tp5016205p5016208.html > > Sent from the ImageJ mailing list archive at Nabble.com. > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.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 |
Free forum by Nabble | Edit this page |