Analyze Particle -> Perimeter

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

Analyze Particle -> Perimeter

Thomas Sadowski
Hello all,
 
 
Does anyone know how ImageJ computes the perimeter of a particle when performing a particle analysis??
 
Thanks in advance,
 
Thomas Sadowski
Southern Connecticut State University
 
_________________________________________________________________
Try Live.com: where your online world comes together - with news, sports, weather, and much more.
http://www.live.com/getstarted
Reply | Threaded
Open this post in threaded view
|

Re: Analyze Particle -> Perimeter

Jonathan Hilmer
My background isn't in Java, so forgive me if I confuse some technical details.

First, it depends on the shape.  If you have a rectangle, it comes
from this code:

/** Returns the perimeter length. */
        public double getLength() {
                double pw=1.0, ph=1.0;
                if (imp!=null) {
                        Calibration cal = imp.getCalibration();
                        pw = cal.pixelWidth;
                        ph = cal.pixelHeight;
                }
                return 2.0*width*pw+2.0*height*ph;
        }

There are other functions called depending on the shape.  I think the
most general is provided by ShapeRoi.java, which is used for irregular
objects:

/**Returns the length of this shape (perimeter, if shape is closed). */
        public double getLength() {
                if(shape==null) return 0.0;
                Rectangle2D r2d = shape.getBounds2D();
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                if(w==0 && h==0) return 0.0;
                PathIterator pIter;
                flatten = true;
                if(flatten) pIter = getFlatteningPathIterator(shape, flatness);
                else pIter = shape.getPathIterator(new AffineTransform());
                double[] par = new double[1];
                parsePath(pIter, par, null, null, null);
                flatten = false;
                return par[0];
        }

The important part is in the last few lines: the function returns the
length of the shape via the 'getPathIterator'.  This isn't unique to
ImageJ, but comes from java.awt.Shape.  I'm not entirely sure how or
when the object in ImageJ becomes associated with or interpreted as a
Java shape, but the perimeter ultimately comes from stepping around
the border of an ImageJ object defined by a Java class.
Reply | Threaded
Open this post in threaded view
|

Re: Analyze Particle -> Perimeter

Gabriel Landini
On Tuesday 18 July 2006 19:16, Jonathan Hilmer wrote:
> I'm not entirely sure how or
> when the object in ImageJ becomes associated with or interpreted as a
> Java shape, but the perimeter ultimately comes from stepping around
> the border of an ImageJ object defined by a Java class.

Regarding he Particle Analyzer, Wayne told me once that:

"I looked the code and it calculates the length of the particle boundary
and subtracts 2-sqrt(2) for each non-adjacent corner, where adjacent
corners are those that are 1 pixel apart. For example, a one pixel
particle has a boundary length of 4 and 4 corners (but only 2 or
counted) so the perimeter is 4-2*(2-sqrt(2)) or 2.8284. For the cross,
the boundary length is 12 and there are 6 non-adjacent corners so the
perimeter is 12 - 6*(2-sqrt(2)) or 8.4853. It helps to zoom in to 3200%
so you can easily see the edges and corners of small particles."

There are other definitions of "perimeter". For instance the Particles8_Plus
plugin calculates it using the Freeman algorithm (stepping along the
perimeter and counting a distance of 1 between side-neighbours and sqrt(2)
between corner-neighbours

The perimeters of the same particles measured with the 2 procedures are
different. Which one is right? Both are because the definition of perimeter
is different.

Cheers,

Gabriel