Login  Register

Re: Get perimeter from image stats

Posted by Rasband, Wayne (NIH/NIMH) [E] on Apr 22, 2014; 12:49am
URL: http://imagej.273.s1.nabble.com/Get-perimeter-from-image-stats-tp5007367p5007381.html

On Apr 19, 2014, at 3:23 PM, boina wrote:

> I'm writing a short script to get stats from images using particle analyzer.
> It's written in jython. The problem I have is that I can get area, mean and
> centroid values but not perimeter or circularity values. The script is as
> follows:

The ImagePlus#getStatistics() method does not calculate perimeter or circularity. You need to use the Roi#getLength() method to get the perimeter and use the area and perimeter to calculate circularity, as follows:

  perimeter = roi.getLength();
  circularity = 4*Math.PI*(stats.area/(perimeter*perimeter));

But this is probably not necessary since the particle analyzer will calculate the perimeter and circularity, as it does in this JavaScript example:

  imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
  IJ.setAutoThreshold(imp, "Default");
  IJ.run("Set Measurements...", "mean perimeter shape");
  min=100; max=400;
  IJ.run(imp, "Analyze Particles...", "size="+min+"-"+max+" clear");
  rt = Analyzer.getResultsTable();
  for (i=0; i<rt.getCounter(); i++) {
     print(i);
     print("  mean: "+rt.getValue("Mean", i));
     print("  perimeter: "+rt.getValue("Perim.", i));
     print("  circularity: "+rt.getValue("Circ.", i));
  }

-wayne


> table = ResultsTable()
> roim  = RoiManager(True)
> pa    = ParticleAnalyzer(ParticleAnalyzer.ADD_TO_MANAGER, Measurements.AREA,
> table, minArea_px, maxArea_px)
> pa.setHideOutputImage(True)
>
> pa.analyze(impFA)
> rm = RoiManager.getInstance()
> rm.runCommand("Save", OUTfilePathROIs)
>
> for roi in RoiManager.getInstance().getRoisAsArray():
> FA.setRoi(roi)
> stats = FA.getStatistics(Measurements.AREA)
>
> print stats.mean
> print stats.perimeters
>
>
> When it gets to mean, it prints it with no problem but when it gets to
> perimeters it says it can't find it.
> Thanks in advanced.
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Get-perimeter-from-image-stats-tp5007367.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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