plotting mean + stdDev (error bars?)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

plotting mean + stdDev (error bars?)

Kenneth Sloan-3
Please be kind - this is my first attempt to use ImageJ to plot graphs.

What I want to do is to plot a graph showing the mean +/- stdDev.

I am currently using "Plot" to plot mean = f(x) - but I'm greedy.

Assume that I have :

float[] xValues;
float[] yValues;
float[] sdValues;

or, if it's easier, replace sdValues with:

float[] above;
float[] below;

The application is to plot pixel values as a f(distance from a fixed point).  
Assume that I can compute the statistics myself - or - if it's easier, provide x,y samples to
a stats package that will plot what I want.

For now, I'm just plotting the mean = f(x) curve, using Plot.  My immediate plan is to export the data from ImageJ and do the fancier stuff in R.  But, I'd be more than pleased to do it all in ImageJ.


--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: plotting mean + stdDev (error bars?)

Kenneth Sloan-3
My abject apologies.  It seems that what I wanted (more or less) was already implemented, and documented.

Mea culpa.

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On 28 Feb 2018, at 20:42 , Kenneth Sloan <[hidden email]> wrote:
>
> Please be kind - this is my first attempt to use ImageJ to plot graphs.
>
> What I want to do is to plot a graph showing the mean +/- stdDev.
>
> I am currently using "Plot" to plot mean = f(x) - but I'm greedy.
>
> Assume that I have :
>
> float[] xValues;
> float[] yValues;
> float[] sdValues;
>
> or, if it's easier, replace sdValues with:
>
> float[] above;
> float[] below;
>
> The application is to plot pixel values as a f(distance from a fixed point).  
> Assume that I can compute the statistics myself - or - if it's easier, provide x,y samples to
> a stats package that will plot what I want.
>
> For now, I'm just plotting the mean = f(x) curve, using Plot.  My immediate plan is to export the data from ImageJ and do the fancier stuff in R.  But, I'd be more than pleased to do it all in ImageJ.
>
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
>
>
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: plotting mean + stdDev (error bars?)

Wayne Rasband-2
In reply to this post by Kenneth Sloan-3
> On Feb 28, 2018, at 9:42 PM, Kenneth Sloan <[hidden email]> wrote:
>
> Please be kind - this is my first attempt to use ImageJ to plot graphs.
>
> What I want to do is to plot a graph showing the mean +/- stdDev.

The following JavaScript example plots stack means with standard deviation as error bars. It requires the latest ImageJ daily build (1.51v17), which adds the Plot.add(type,yvalues) method.

-wayne

  img = IJ.openImage("http://wsr.imagej.net/images/t1-head.zip");
  stack = img.getStack();
  n = stack.size();
  meanValues = new Array(n);
  sdValues = new Array(n);
  for (i=0; i<n; i++) {
     ip = stack.getProcessor(i+1);
     ip.setRoi(105,85,65,55);
     stats = ip.getStatistics();
     meanValues[i] = stats.mean;
     sdValues[i] = stats.stdDev;;
  }
  plot = new Plot("Stack Means with Error Bars", "Slice", "Mean");
  plot.add("line", meanValues);
  plot.add("error bars", sdValues);
  plot.show();


> I am currently using "Plot" to plot mean = f(x) - but I'm greedy.
>
> Assume that I have :
>
> float[] xValues;
> float[] yValues;
> float[] sdValues;
>
> or, if it's easier, replace sdValues with:
>
> float[] above;
> float[] below;
>
> The application is to plot pixel values as a f(distance from a fixed point).  
> Assume that I can compute the statistics myself - or - if it's easier, provide x,y samples to
> a stats package that will plot what I want.
>
> For now, I'm just plotting the mean = f(x) curve, using Plot.  My immediate plan is to export the data from ImageJ and do the fancier stuff in R.  But, I'd be more than pleased to do it all in ImageJ.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: plotting mean + stdDev (error bars?)

Kenneth Sloan-3
Thanks.  I forgot my usual caveat that I deal in Java plugins, not JavaScript.  I'm sure the change
will benefit someone.  Again - my abject apologies for finding the Plot API, but not reading it carefully enough.  I simply missed the "addErrorBars" method, which magically implements exactly what I asked for.
Once again, I am impressed.

Just to close the loop, here's the code that worked for me (once I actually *read* the documentation).
"Distance" is binned by specifying lowerBounds for each bin.  All bins are the same width.  Plotted x values are shifted to the middle of the bin (perhaps overkill).  Data were gathered from a 768x768 RGB image of human retina, with luminance values in [0, 255], transformed to [0.0,1.0].  Distance is measured from a central x,y location specified earlier.  The larger error bars are due to gross structural features in the image (vasculature, optic nerve head) which I now need to work on removing...

        double maxD = ...find max distance...
        int nBins = ...choose the number of bins (100 in this example)
        double[] lowerBounds = ...create an array of lower bounds for bins (binned by distance)
        double[] means = ...calculate mean value for every bin (guaranteed to be in [0.0, 1.0])
        double[] stdDevs = ...calculate stdDev value for every bin

        String title = "QAF spatial distribution";
        String xLabel = "distance from fovea";
        String yLabel = "mean QAF";
        float[] xValues = new float[nBins];
        float[] yValues = new float[nBins];
        float[] errorBars = new float[nBins];
        double toMiddleOfBin = (lowerBounds[1]-lowerBounds[0])/2.0;
        for(int b=0;b<nBins;b++)
            {
              xValues[b] = (float)(lowerBounds[b] + toMiddleOfBin);
                yValues[b] = (float)means[b];
                errorBars[b] = (float)stdDevs[b];
            }
        Plot plot = new Plot(title,xLabel,yLabel,xValues,yValues);
        plot.setLimits(0.0, maxD, 0.0, 1.0);
        plot.addErrorBars(errorBars);
        PlotWindow plotWindow = plot.show();

and, here's the result:





--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On 1 Mar 2018, at 00:25 , Wayne Rasband <[hidden email]> wrote:
>
>> On Feb 28, 2018, at 9:42 PM, Kenneth Sloan <[hidden email] <mailto:[hidden email]>> wrote:
>>
>> Please be kind - this is my first attempt to use ImageJ to plot graphs.
>>
>> What I want to do is to plot a graph showing the mean +/- stdDev.
>
> The following JavaScript example plots stack means with standard deviation as error bars. It requires the latest ImageJ daily build (1.51v17), which adds the Plot.add(type,yvalues) method.
>
> -wayne
>
>  img = IJ.openImage("http://wsr.imagej.net/images/t1-head.zip <http://wsr.imagej.net/images/t1-head.zip>");
>  stack = img.getStack();
>  n = stack.size();
>  meanValues = new Array(n);
>  sdValues = new Array(n);
>  for (i=0; i<n; i++) {
>     ip = stack.getProcessor(i+1);
>     ip.setRoi(105,85,65,55);
>     stats = ip.getStatistics();
>     meanValues[i] = stats.mean;
>     sdValues[i] = stats.stdDev;;
>  }
>  plot = new Plot("Stack Means with Error Bars", "Slice", "Mean");
>  plot.add("line", meanValues);
>  plot.add("error bars", sdValues);
>  plot.show();
>
>
>> I am currently using "Plot" to plot mean = f(x) - but I'm greedy.
>>
>> Assume that I have :
>>
>> float[] xValues;
>> float[] yValues;
>> float[] sdValues;
>>
>> or, if it's easier, replace sdValues with:
>>
>> float[] above;
>> float[] below;
>>
>> The application is to plot pixel values as a f(distance from a fixed point).  
>> Assume that I can compute the statistics myself - or - if it's easier, provide x,y samples to
>> a stats package that will plot what I want.
>>
>> For now, I'm just plotting the mean = f(x) curve, using Plot.  My immediate plan is to export the data from ImageJ and do the fancier stuff in R.  But, I'd be more than pleased to do it all in ImageJ.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html <http://imagej.nih.gov/ij/list.html>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Screen Shot 2018-03-01 at 09.53.42 .png (138K) Download Attachment