Login  Register

Re: Calculating Encircled Energy

Posted by Michael Schmid on Jan 26, 2014; 12:05pm
URL: http://imagej.273.s1.nabble.com/Calculating-Encircled-Energy-tp5006279p5006283.html

Hi Angel,

ImageJ does not support 'soft' boundaries for selections or partially
selected pixels.

What you can do:

(i) Enlarge the image with nearest neighbor interpolation. When enlarging
by a factor large enough (say, 4 or more), you will get a reasonable
approximation to subpixel resolution.

(ii) Write a plugin, or if you have not too large circles and not too many
of them, a macro will be good enough. Roughly like this (does not work for
RGB):

xc=3.2;yc=5.2; //center (integer values are defined as pixel center)
radius=2.6;    //radius
//if you want to see the selection:
//makeOval(xc+0.5-radius,yc+0.5-radius,2*radius,2*radius);

sum=0;
area=0;
for (y=floor(yc-radius-0.5); y<=ceil(yc+radius+0.5); y++)
  for (x=floor(xc-radius-0.5); x<=ceil(xc+radius+0.5); x++) {
    r=sqrt((x-xc)*(x-xc)+(y-yc)*(y-yc));
    if (r<=radius-0.5) {
      sum+=getPixel(x,y);
      area++;
    } else if (r<=radius+0.5) {
      weight = (radius+0.5)-r;
      sum+=getPixel(x,y)*weight;
      area+=weight;
    }
  }
print ("sum="+d2s(sum,2)+", area="+d2s(area,2));

function ceil(x) {
  return -floor(-x);
}

Note that the area won't be exactly the area of a circle, r^2*pi but
slightly more, because it does not accurately calculate the intersection
of a circle and the pixel. It simply uses pixel weights decreasing from 1
to 0. If the exact circle line passes through the center of a pixel, it
gets a weight of 0.5.

Michael
_______________________________________________________________________

On Sun, January 26, 2014 07:24, angel.leigh wrote:

> Hi
>
> I've been calcuating the energy in some images using progressively larger
> circlar regions, and summing the pixels.  However, I would like to be able
> to count the "edge" pixels.  If a pixel falls half-in and half-out, to
> count
> half the value of the pixel.  This is more important because I am
> calculating the centriod, which is never perfectly centered on a pixel.
>
> I know that somebody has to have already figured this out, but I can't
> seem
> to find it.  I've searched "encircled energy," "point spread function,"
> and
> "power in the bucket" but can't seem to find one that partially counts
> border pixels.
>
> If anyone could point me in the right direction I would appreciate it.
>
> thx,
> Angel
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Calculating-Encircled-Energy-tp5006279.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