bug with summarize ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

bug with summarize ?

Thomas Boudier
Hi,

I am encountering a strange behaviour with ResultsTable, the summarize
is ok when I use it just after analyseparticles, but when I use it after
importing results only the 3 first columns are summarized; I am running
Ij 1.46m on linux. You can reproduce the pb with this macro :

run("Blobs (25K)");
run("Duplicate...", "title=blobs-1.gif");
run("Set Measurements...", "area mean standard fit shape display
redirect=blobs.gif decimal=3");
setThreshold(126, 255);
run("Convert to Mask");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
show=Nothing display clear");
saveAs("Results", "/home/thomas/Results.xls");
run("Summarize");
wait(5000);
selectWindow("Results");
run("Close");
open("/home/thomas/Results.xls");
run("Summarize");

thanks for any suggestions.

Thomas

--
   /**********************************************************/
      Thomas Boudier, MCU Université Pierre et Marie Curie,
      Modélisation Cellulaire et Imagerie Biologique (EE1),
      IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
      Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
/*******************************************************/
Reply | Threaded
Open this post in threaded view
|

Re: bug with summarize ?

Michael Schmid
Hi Thomas,

your problem seems to come from the code in ij.plugin.filter.Analyzer.summarize() - actually, I don't understand why it does not simply take the columns one by one and summarize them.

Below is a macro similar to the 'summarize' function that does what I have proposed above.
Compared to the built-in 'summarize', it has the disadvantage that its output is not separate from the normal results.

A limitation of both the built-in and this summarize function:
Angles are not averaged properly. If you have -179° and +179°, the average is 0, not 180°.
One should not average over angles but rather over sin(angle), cos(angle) and take atan2 of the averages if the angles have a 360 degree range. For angles with a 180° range like the 'fit ellipse' angles, one should average the moments used to calculate the angles.  Unfortunately, I see no way to do this consistently.

Michael
________________________________________________________________

// Summarize macro

headings = split(String.getResultsHeadings);
nRows = nResults();
nCol = lengthOf(headings);
if (nRows<2 || nCol<1) exit("Not enough results");
if (headings[0]=="Label") firstCol=1;
else firstCol=0;
min = newArray(nCol);
max = newArray(nCol);
sum = newArray(nCol);
sum2 = newArray(nCol);

for (i=0; i<nCol; i++) {
  min[i] = 1e300;
  max[i] = -1e300;
}

for (row=0; row<nRows; row++) {
  for (col=firstCol; col<lengthOf(headings); col++) {
    v = getResult(headings[col],row);
    if (v<min[col]) min[col]=v;
    if (v>max[col]) max[col]=v;
    sum[col]+=v;
    sum2[col]+=v*v;
  }
}

setResult("Label", nRows+0, "min");
setResult("Label", nRows+1, "max");
setResult("Label", nRows+2, "mean");
setResult("Label", nRows+3, "SD");
for (col=firstCol; col<lengthOf(headings); col++) {
  setResult(headings[col], nRows+0, min[col]);
  setResult(headings[col], nRows+1, max[col]);
  setResult(headings[col], nRows+2, sum[col]/nRows);
  setResult(headings[col], nRows+3, sqrt((sum2[col]-sum[col]*sum[col]/nRows)/(nRows-1)));
}


________________________________________________________________
On Apr 27, 2012, at 15:48, Thomas Boudier wrote:

> Hi,
>
> I am encountering a strange behaviour with ResultsTable, the summarize is ok when I use it just after analyseparticles, but when I use it after importing results only the 3 first columns are summarized; I am running Ij 1.46m on linux. You can reproduce the pb with this macro :
>
> run("Blobs (25K)");
> run("Duplicate...", "title=blobs-1.gif");
> run("Set Measurements...", "area mean standard fit shape display redirect=blobs.gif decimal=3");
> setThreshold(126, 255);
> run("Convert to Mask");
> run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing display clear");
> saveAs("Results", "/home/thomas/Results.xls");
> run("Summarize");
> wait(5000);
> selectWindow("Results");
> run("Close");
> open("/home/thomas/Results.xls");
> run("Summarize");
>
> thanks for any suggestions.
>
> Thomas
>
> --
>  /**********************************************************/
>     Thomas Boudier, MCU Université Pierre et Marie Curie,
>     Modélisation Cellulaire et Imagerie Biologique (EE1),
>     IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
>     Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
> /*******************************************************/
Reply | Threaded
Open this post in threaded view
|

Re: bug with summarize ?

Thomas Boudier
Hi Michael,

Thanks for your answer, this bug appears on the different flavours of IJ
(IJ1, IJ2, Fiji) on Linux and Mac. Anyway thanks for this nice macro.

Thomas


Le 03/05/2012 13:59, Michael Schmid a écrit :

> Hi Thomas,
>
> your problem seems to come from the code in ij.plugin.filter.Analyzer.summarize() - actually, I don't understand why it does not simply take the columns one by one and summarize them.
>
> Below is a macro similar to the 'summarize' function that does what I have proposed above.
> Compared to the built-in 'summarize', it has the disadvantage that its output is not separate from the normal results.
>
> A limitation of both the built-in and this summarize function:
> Angles are not averaged properly. If you have -179° and +179°, the average is 0, not 180°.
> One should not average over angles but rather over sin(angle), cos(angle) and take atan2 of the averages if the angles have a 360 degree range. For angles with a 180° range like the 'fit ellipse' angles, one should average the moments used to calculate the angles.  Unfortunately, I see no way to do this consistently.
>
> Michael
> ________________________________________________________________
>
> // Summarize macro
>
> headings = split(String.getResultsHeadings);
> nRows = nResults();
> nCol = lengthOf(headings);
> if (nRows<2 || nCol<1) exit("Not enough results");
> if (headings[0]=="Label") firstCol=1;
> else firstCol=0;
> min = newArray(nCol);
> max = newArray(nCol);
> sum = newArray(nCol);
> sum2 = newArray(nCol);
>
> for (i=0; i<nCol; i++) {
>    min[i] = 1e300;
>    max[i] = -1e300;
> }
>
> for (row=0; row<nRows; row++) {
>    for (col=firstCol; col<lengthOf(headings); col++) {
>      v = getResult(headings[col],row);
>      if (v<min[col]) min[col]=v;
>      if (v>max[col]) max[col]=v;
>      sum[col]+=v;
>      sum2[col]+=v*v;
>    }
> }
>
> setResult("Label", nRows+0, "min");
> setResult("Label", nRows+1, "max");
> setResult("Label", nRows+2, "mean");
> setResult("Label", nRows+3, "SD");
> for (col=firstCol; col<lengthOf(headings); col++) {
>    setResult(headings[col], nRows+0, min[col]);
>    setResult(headings[col], nRows+1, max[col]);
>    setResult(headings[col], nRows+2, sum[col]/nRows);
>    setResult(headings[col], nRows+3, sqrt((sum2[col]-sum[col]*sum[col]/nRows)/(nRows-1)));
> }
>
>
> ________________________________________________________________
> On Apr 27, 2012, at 15:48, Thomas Boudier wrote:
>
>> Hi,
>>
>> I am encountering a strange behaviour with ResultsTable, the summarize is ok when I use it just after analyseparticles, but when I use it after importing results only the 3 first columns are summarized; I am running Ij 1.46m on linux. You can reproduce the pb with this macro :
>>
>> run("Blobs (25K)");
>> run("Duplicate...", "title=blobs-1.gif");
>> run("Set Measurements...", "area mean standard fit shape display redirect=blobs.gif decimal=3");
>> setThreshold(126, 255);
>> run("Convert to Mask");
>> run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing display clear");
>> saveAs("Results", "/home/thomas/Results.xls");
>> run("Summarize");
>> wait(5000);
>> selectWindow("Results");
>> run("Close");
>> open("/home/thomas/Results.xls");
>> run("Summarize");
>>
>> thanks for any suggestions.
>>
>> Thomas
>>
>> --
>>   /**********************************************************/
>>      Thomas Boudier, MCU Université Pierre et Marie Curie,
>>      Modélisation Cellulaire et Imagerie Biologique (EE1),
>>      IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
>>      Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
>> /*******************************************************/

--
   /**********************************************************/
      Thomas Boudier, MCU Université Pierre et Marie Curie,
      Modélisation Cellulaire et Imagerie Biologique (EE1),
      IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
      Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
/*******************************************************/
Reply | Threaded
Open this post in threaded view
|

Re: bug with summarize ?

Gabriel Landini
On Friday 04 May 2012 11:38:16 you wrote:
> Thanks for your answer, this bug appears on the different flavours of IJ
> (IJ1, IJ2, Fiji) on Linux and Mac. Anyway thanks for this nice macro.

Now that we are discussing this... One problem of summarizing data is that we
cannot expect the summary to be meaningful without knowing first what the data
is.
The "angle" problem was already highlighted. Colour hue is another circular
scale mapped into a linear one where summaries make no sense. I have some
procedures where I need to flag if a data value was actually computed (if not,
that cell should not be considered in a summary, so adding a "-1" type of flag
messes up the summary), other columns might have pixel coordinates, or  just
labels, but not quantitative numbers. So blind summaries of tables might not
be correct in every case and are likely to cause some problems.

I know that this might not be feasible, but for future reference, it would be
perhaps useful to be able to tag the columns in the results table, so that
kind of problem is avoided. That way one could process and plot data in safer
and more meaningful ways.

Cheers

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: bug with summarize ?

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Thomas Boudier
On Apr 27, 2012, at 9:48 AM, Thomas Boudier wrote:

> Hi,
>
> I am encountering a strange behaviour with ResultsTable, the summarize
> is ok when I use it just after analyseparticles, but when I use it after
> importing results only the 3 first columns are summarized; I am running
> Ij 1.46m on linux. You can reproduce the pb with this macro :
>
> run("Blobs (25K)");
> run("Duplicate...", "title=blobs-1.gif");
> run("Set Measurements...", "area mean standard fit shape display
> redirect=blobs.gif decimal=3");
> setThreshold(126, 255);
> run("Convert to Mask");
> run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
> show=Nothing display clear");
> saveAs("Results", "/home/thomas/Results.xls");
> run("Summarize");
> wait(5000);
> selectWindow("Results");
> run("Close");
> open("/home/thomas/Results.xls");
> run("Summarize");
>
> thanks for any suggestions.
>
> Thomas

This bug is fixed in the ImageJ 1.46n daily build.

Here is a slightly simplified version of Thomas' helpful test macro:

  run("Blobs (25K)");
  run("Set Measurements...", "area mean standard fit shape");
  setThreshold(126, 255);
  run("Analyze Particles...", "display clear");
  saveAs("Results", getDirectory("home")+"Results.xls");
  run("Summarize");
  wait(3000);
  open(getDirectory("home")+"Results.xls");
  run("Summarize");

-wayne
Reply | Threaded
Open this post in threaded view
|

select all in roiManager?

Cammer, Michael
Hi.
In a macro I want to select all ROIs in the ROIManager and measure them.
Is there a selectAll type command or do I have to make a new array 0..roiManager("count")-1 and fill it from 0 to roiManager("count")-1 to do this with the roiManager("select", indexes) command?

example of what I want to do:
  run("Clear Results");
  run("Set Measurements...", "area mean standard centroid shape redirect=None decimal=3");
**roiManager Select All**  
  roiManager("Measure");
  selectWindow("Results");
  IJ.renameResults(t);
  saveAs("text", path);

Thank you!

________________________________________________________
Michael Cammer, Assistant Research Scientist
Skirball Institute of Biomolecular Medicine
Lab: (212) 263-3208  Cell: (914) 309-3270
Reply | Threaded
Open this post in threaded view
|

Re: select all in roiManager?

BROUILLY NICOLAS
Hi,

I guess you could use the :

roiManager("Deselect");

command line. By deselecting all ROI, you'll run the roiManager("Measure") command line on all ROIs of you ROI set.

Hope that's what you wanted !

Nico

Le 4 mai 2012 à 16:17, Cammer, Michael a écrit :

Hi.
In a macro I want to select all ROIs in the ROIManager and measure them.
Is there a selectAll type command or do I have to make a new array 0..roiManager("count")-1 and fill it from 0 to roiManager("count")-1 to do this with the roiManager("select", indexes) command?

example of what I want to do:
 run("Clear Results");
 run("Set Measurements...", "area mean standard centroid shape redirect=None decimal=3");
**roiManager Select All**
 roiManager("Measure");
 selectWindow("Results");
 IJ.renameResults(t);
 saveAs("text", path);

Thank you!

________________________________________________________
Michael Cammer, Assistant Research Scientist
Skirball Institute of Biomolecular Medicine
Lab: (212) 263-3208  Cell: (914) 309-3270

Nicolas Brouilly, PhD Student
Equipe Gieseler, "Pathologies du muscle chez C. elegans"

Centre de Génétique et de Physiologie Moléculaires et Cellulaires
UMR CNRS 5534
Université Claude Bernard Lyon 1
Bâtiment Gregor Mendel, 5ème étage
16, rue Raphaël Dubois
F-69622 Villeurbanne Cedex

[hidden email]<mailto:[hidden email]>
Lab : +0033 (0)4 72 43 29 48
Cel : +0033 (0)6 42 91 53 19
Reply | Threaded
Open this post in threaded view
|

Re: select all in roiManager? -- problem solved

Cammer, Michael
In reply to this post by Cammer, Michael
Actually, this works fine for what we need.  Thanks-
Michael



macro "measure all ROI Manager and save results" {
  for (k=1; k<=nImages; k++) {
    selectImage(k);
    measureAllROIMangagerAndSave();
  }
}


function measureAllROIMangagerAndSave() {
  path = getDirectory("image");
  t = getTitle;
  if (endsWith(t, "tif"))
   t = replace(t, "tif", "txt");
  t = "automeasurements_"+t;
  run("Clear Results");
  run("Set Measurements...", "area mean standard centroid shape redirect=None decimal=3");
  a = newArray(roiManager("count"));
  for (i=0; i<roiManager("count"); i++) a[i]=i;
    roiManager("select", a);
  roiManager("Measure");
  selectWindow("Results");
  IJ.renameResults(t);
  saveAs("text", path+t);
  run("Close");
}  




________________________________________________________
Michael Cammer, Assistant Research Scientist Skirball Institute of Biomolecular Medicine
Lab: (212) 263-3208  Cell: (914) 309-3270
Reply | Threaded
Open this post in threaded view
|

Re: bug with summarize ?

Thomas Boudier
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
Hi Wayne,

Thanks a lot. On my computer (linux, openjdk) I need to close the
Results window before re-opening it, if not the summarize command does
not work.

  selectWindow("Results");
   run("Close");

cheers,

Thomas


Le 04/05/2012 15:43, Rasband, Wayne (NIH/NIMH) [E] a écrit :
>    run("Blobs (25K)");
>    run("Set Measurements...", "area mean standard fit shape");
>    setThreshold(126, 255);
>    run("Analyze Particles...", "display clear");
>    saveAs("Results", getDirectory("home")+"Results.xls");
>    run("Summarize");
>    wait(3000);
>    open(getDirectory("home")+"Results.xls");
>    run("Summarize");

--
   /**********************************************************/
      Thomas Boudier, MCU Université Pierre et Marie Curie,
      Modélisation Cellulaire et Imagerie Biologique (EE1),
      IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
      Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
/*******************************************************/