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 |
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 |
Hi Avita,
Thank you for the pointer. It works well with a rectangular ROI (I get the mean intensity inside the ROI). However, using this with a segmented line ROI returns the mean intensity of the whole image, not the mean intensity value for the segmented line ROI (given manually by using "Measure" with the ROI activated). What am I doing wrong here? - open a sample image. - draw a segmented line 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); imp.setRoi(roi, false); var stat = imp.getStatistics(); var mean = stat.mean; IJ.log(mean); the value returned is the mean intensity of the whole image, not of the segmented line ROI. Christophe On Wed, Jun 14, 2017 at 1:41 PM, Avital Steinberg <[hidden email] > wrote: > 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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Christophe,
The command you are using is different from what I am using. I am using: var stats = imp.get*All*Statistics(); And you are using: var stat = imp.getStatistics(); I hope this helps, Avital On Wed, Jun 14, 2017 at 4:15 PM, Christophe Leterrier < [hidden email]> wrote: > Hi Avita, > > Thank you for the pointer. It works well with a rectangular ROI (I get the > mean intensity inside the ROI). However, using this with a segmented line > ROI returns the mean intensity of the whole image, not the mean intensity > value for the segmented line ROI (given manually by using "Measure" with > the ROI activated). What am I doing wrong here? > > - open a sample image. > - draw a segmented line 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); > imp.setRoi(roi, false); > var stat = imp.getStatistics(); > > var mean = stat.mean; > IJ.log(mean); > > the value returned is the mean intensity of the whole image, not of the > segmented line ROI. > > > > Christophe > > On Wed, Jun 14, 2017 at 1:41 PM, Avital Steinberg < > [hidden email]> wrote: > >> 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 >> > > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Avital,
Unfortunately it does not make a difference. getAllStatistics is a slower getStatistics that is more precise in certain specific cases if I remember correctly. Both fail to return the mean value along the segmented line ROI. Christophe On Wed, Jun 14, 2017 at 3:27 PM, Avital Steinberg <[hidden email] > wrote: > Hi Christophe, > The command you are using is different from what I am using. I am using: > > var stats = imp.get*All*Statistics(); > > And you are using: > > var stat = imp.getStatistics(); > > I hope this helps, > Avital > > > > > On Wed, Jun 14, 2017 at 4:15 PM, Christophe Leterrier < > [hidden email]> wrote: > >> Hi Avita, >> >> Thank you for the pointer. It works well with a rectangular ROI (I get >> the mean intensity inside the ROI). However, using this with a segmented >> line ROI returns the mean intensity of the whole image, not the mean >> intensity value for the segmented line ROI (given manually by using >> "Measure" with the ROI activated). What am I doing wrong here? >> >> - open a sample image. >> - draw a segmented line 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); >> imp.setRoi(roi, false); >> var stat = imp.getStatistics(); >> >> var mean = stat.mean; >> IJ.log(mean); >> >> the value returned is the mean intensity of the whole image, not of the >> segmented line ROI. >> >> >> >> Christophe >> >> On Wed, Jun 14, 2017 at 1:41 PM, Avital Steinberg < >> [hidden email]> wrote: >> >>> 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 >>> >> >> > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by lechristophe
> 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 |
Free forum by Nabble | Edit this page |