Login  Register

Re: Two result tables, possible?

Posted by Rasband, Wayne (NIH/NIMH) [E] on Jun 07, 2010; 8:27pm
URL: http://imagej.273.s1.nabble.com/Two-result-tables-possible-tp3687562p3687573.html

On Jun 7, 2010, at 2:21 AM, Aryeh Weiss wrote:

> Rasband, Wayne (NIH/NIMH) [E] wrote:
>>> Dear list,
>>>
>>> Is it possible to create two different result tables in the same macro?
>>> For example I'm working with two stacks, applying some measurements
>>> on the nuclei and then on the fluorescent particles in every nucleus.
>>> So I need one result table for the nuclei and the other for the included
>>> particles, because every one has its own measurements.
>>> Is it possible in imagej?
>>
>> You can create multiple result tables in the 1.44c4 daily build by using the new "Rename" command, available in the File menu of Results windows. Here is an example macro that uses the corresponding IJ.renameResults() macro function to create two result tables.
>>
>>   run("Blobs (25K)");
>>   setAutoThreshold("Default");
>>   run("Analyze Particles...", "display clear");
>>   IJ.renameResults("Unsmoothed");
>>   run("Gaussian Blur...", "sigma=2");
>>   setAutoThreshold("Default");
>>   run("Analyze Particles...", "display clear");
>>   IJ.renameResults("Smoothed");
>>
>> -wayne
>>
>
> This is great!
>
> Can the functions that access the results table (getResults, etc) select
> which result table to use?

Macro functions like getResults() only work with the primary results table so you have to rename the table you want to access to "Results". I have included an example. Plugins and scripts can get a reference to the underlining ResultsTable object and use the rt.getValue() method.

-wayne

   setBatchMode(true);
   run("Blobs (25K)");
   run("Set Measurements...", "area mean min decimal=2");
   setAutoThreshold("Default");
   run("Analyze Particles...", "display clear add");
   IJ.renameResults("Unsmoothed");
   run("Gaussian Blur...", "sigma=2");
   n = roiManager("count");
   for (i=0; i<n; i++) {
       roiManager("select", i)
       run("Measure");
   }
   mean1 = newArray(n);
   mean2 = newArray(n);
   IJ.renameResults("Smoothed");
   selectWindow("Unsmoothed");
   IJ.renameResults("Results");
   for (i=0; i<n; i++)
       mean1[i] = getResult("Mean", i);
   selectWindow("Smoothed");
   IJ.renameResults("Results");
   for (i=0; i<n; i++)
       mean2[i] = getResult("Mean", i);
   run("Clear Results");
   for (i=0; i<n; i++) {
       setResult("Mean1", i, mean1[i]);
       setResult("Mean2", i, mean2[i]);
       setResult("%Difference", i, (mean1[i]-mean2[i])*100/mean1[i]);
   }
   updateResults();