Login  Register

Re: Get ROI statistics in Javascript?

Posted by Wayne Rasband-2 on Jun 14, 2017; 6:35pm
URL: http://imagej.273.s1.nabble.com/Get-ROI-statistics-in-Javascript-tp5018887p5018896.html

> On Jun 14, 2017, at 5:24 AM, Christophe Leterrier <[hidden email]> wrote:
>
> Dear ImageJers,
>
> I'm trying to write a javascript snippet that retrieves a ROI from the ROI
> manager, and returns the mean intensity but I can't seem to find out how to
> do it.

The following JavaScript code demonstrates how to retrieve the mean of the pixel values along a segmented line selection.

-wayne

  imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");  
  measurements = Measurements.MEAN;
  rt = new ResultsTable();
  analyzer = new Analyzer(imp, measurements,rt);
  xpoints = [50,112,181,203];
  ypoints = [98,61,74,122];
  imp.setRoi(new PolygonRoi(xpoints,ypoints,Roi.POLYLINE));
  analyzer.measure();
  mean = rt.getValue("Mean",0);
  print("Mean="+mean);


> Here am I so far:
>
> - open a sample image
> - draw a ROi on it, store it in the ROI manager
> - run this script:
>
> importClass(Packages.ij.IJ);
> importClass(Packages.ij.plugin.frame.RoiManager);
> importClass(Packages.ij.gui.Roi);
>
> var imp = IJ.getImage();
> var rm = RoiManager.getInstance();
>
> var roi = rm.getRoi(0);
> roi.setImage(imp);
> var stat = roi.getStatistics();
> IJ.log(stat.mean);
>
> the "mean" property of the ImageStatistic returned by getStatistics() has a
> value of NaN. How come? How to access the roi statistics in a purely
> programmatic manner (ie without displaying stuff)?
>
> Thanks for your help,
>
> Christophe
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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