Login  Register

Re: Get ROI statistics in Javascript?

Posted by Avital Steinberg on Jun 14, 2017; 11:41am
URL: http://imagej.273.s1.nabble.com/Get-ROI-statistics-in-Javascript-tp5018887p5018890.html

Hi Christophe,
You can get the Roi statistics like this:

imp.setRoi(roi, false);
var stats = imp.getAllStatistics();
var median = stats.median;

The stats objects is an ImageStatistics object, so you can see which fields
it has here:

https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html

Good luck,
Avital

On Wed, Jun 14, 2017 at 12:24 PM, 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.
>
> 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