Login  Register

Re: Raw data from Plot Profiles

Posted by Wayne Rasband on Mar 06, 2006; 5:45am
URL: http://imagej.273.s1.nabble.com/Raw-data-from-Plot-Profiles-tp3703513p3703514.html

 > Thanks for getting back to me so fast. I think the macro you
 > sent me calculates the "grand average" and "grand standard
 > deviation" of the Plot Profile. What I am looking for is
 > the standard deviation of each individual point in the Plot
 > Profile Y intensity column. Since each Y value is the mean
 > of the vertical line of pixels of a selected image there
 > is a significant amount of useful info described in the
 > variability around that mean (each Y intensity value in
 > the Plot Profile). Is there a macro that will add another
 > column in the Plot Profile data list that would contain the
 > standard deviation of each Y intensity value?

Here is a profile plotting macro that plots the standard deviation of  
each Y value as an error bar and lists the Y values and standard  
deviations in the "Results" table.

-wayne

   if (selectionType!=0)
       exit("Rectangular selection required");
   if (bitDepth==24)
       exit("Grayscale image required");
   getSelectionBounds(xbase, ybase, width, height);
   a = newArray(height);
   profile = newArray(width);
   sd = newArray(width);
   for (x=xbase; x<xbase+width; x++) {
       for (y=ybase; y<ybase+height; y++)
           a[y-ybase] = getPixel(x, y);
       sum = 0;
       for (i=0; i<height; i++)
           sum = sum + a[i];
       mean = sum/height;
       profile[x-xbase] = mean;
       sum2 = 0;
       for (i=0; i<height; i++)
           sum2 = (a[i]-mean)*(a[i]-mean);
       sd[x-xbase] = sqrt(sum2/height);;
   }
   Plot.create("Profile Plot", "X", "Value", profile);
   Plot.add("error bars", sd);
   run("Clear Results");
   for (i=0; i<width; i++) {
       setResult("Mean", i, profile[i]);
       setResult("SD", i, sd[i]);
   }
   updateResults;