Hi,
I'm trying to do some measurements using Javascript. When I run the following code on the attached image: importClass(Packages.ij.IJ); importClass(Packages.ij.plugin.frame.RoiManager); importClass(Packages.ij.io.OpenDialog); importClass(Packages.ij.io.DirectoryChooser); importClass(Packages.java.io.File); importClass(Packages.ij.gui.GenericDialog); importClass(Packages.ij.util.Tools); importClass(Packages.ij.plugin.Duplicator); importClass(Packages.ij.measure.ResultsTable); importClass(Packages.ij.ImagePlus); importClass(Packages.ij.process.ImageProcessor); importClass(Packages.ij.gui.OvalRoi); IJ = IJ(); rm = RoiManager.getInstance(); rt = ResultsTable.getResultsTable(); if (rm==null) rm = new RoiManager(); if (rt==null) rt = new ResultsTable(); impProc = IJ.getImage(); impProc.setRoi(new OvalRoi(405,585,54,57)); IJ.run("ROI Manager...", ""); rm.addRoi(impProc.getRoi()); rm.select(impProc, 0); ipProc = impProc.getProcessor(); stats = ipProc.getStatistics(); mean = stats.mean; print("The mean is: " + mean); stats2 = impProc.getStatistics(); mean2 = stats.mean; print("Mean2 is: " + mean2); I get the following output: The mean is: 49.10071474983756 Mean2 is: 49.10071474983756 However, if I use analyze, measure in the graphical user interface, I get a mean intensity value of 60.8043. What might the problem be? Thanks, Avital -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html inputImageJpg.jpg (164K) Download Attachment |
On Monday 24 Aug 2015 21:42:23 Avital Steinberg wrote:
> Hi, > I'm trying to do some measurements using Javascript. When I run the > following code on the attached image: > However, if I use analyze, measure in the graphical user interface, I get a > mean intensity value of 60.8043. > > > What might the problem be? With that code, you are computing the mean of the rectangular region bounding the circular ROI, I think. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Gabriel,
I'm using the same ROI in both cases, so I should get the same value regardless of the shape of the ROI. So this isn't the answer. Thanks, Avital On Mon, Aug 24, 2015 at 10:33 PM, Gabriel Landini <[hidden email]> wrote: > On Monday 24 Aug 2015 21:42:23 Avital Steinberg wrote: > > Hi, > > I'm trying to do some measurements using Javascript. When I run the > > following code on the attached image: > > > However, if I use analyze, measure in the graphical user interface, I > get a > > mean intensity value of 60.8043. > > > > > > What might the problem be? > > With that code, you are computing the mean of the rectangular region > bounding > the circular ROI, I think. > Cheers > > Gabriel > > -- > 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 Gabriel Landini
Actually, Gabriel - you may be right that it's measuring the bounding
rectangle, because when I tried to use the ImageProcessor getHistogram function in Javascript, it measured more pixeis than it did in the macro. I think it's a bug, so I submitted a bug report. Correct me if I'm wrong - I'll be very happy if changing my code would help. Thanks, Avital On Mon, Aug 24, 2015 at 10:33 PM, Gabriel Landini <[hidden email]> wrote: > On Monday 24 Aug 2015 21:42:23 Avital Steinberg wrote: > > Hi, > > I'm trying to do some measurements using Javascript. When I run the > > following code on the attached image: > > > However, if I use analyze, measure in the graphical user interface, I > get a > > mean intensity value of 60.8043. > > > > > > What might the problem be? > > With that code, you are computing the mean of the rectangular region > bounding > the circular ROI, I think. > Cheers > > Gabriel > > -- > 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 Avital Steinberg
> On Aug 24, 2015, at 2:42 PM, Avital Steinberg <[hidden email]> wrote: > > Hi, > I'm trying to do some measurements using Javascript. When I run the > following code on the attached image: You need to assign the ROI to the ImageProcessor by calling ImageProcessor.setRoi(). This JavaScript img = IJ.getImage(); roi = new OvalRoi(405,585,54,57); img.setRoi(roi); ip = img.getProcessor(); ip.setRoi(roi); stats = ip.getStatistics(); print("The mean is: " + stats.mean); stats2 = img.getStatistics(); print("Mean2 is: " + stats2.mean); outputs The mean is: 60.80429397192403 Mean2 is: 60.80429397192403 If you remove "ip.setRoi(roi);” and run it again you get The mean is: 49.10071474983756 Mean2 is: 60.80429397192403 -wayne > importClass(Packages.ij.IJ); > importClass(Packages.ij.plugin.frame.RoiManager); > importClass(Packages.ij.io.OpenDialog); > importClass(Packages.ij.io.DirectoryChooser); > importClass(Packages.java.io.File); > importClass(Packages.ij.gui.GenericDialog); > importClass(Packages.ij.util.Tools); > importClass(Packages.ij.plugin.Duplicator); > importClass(Packages.ij.measure.ResultsTable); > importClass(Packages.ij.ImagePlus); > importClass(Packages.ij.process.ImageProcessor); > importClass(Packages.ij.gui.OvalRoi); > > IJ = IJ(); > rm = RoiManager.getInstance(); > rt = ResultsTable.getResultsTable(); > if (rm==null) rm = new RoiManager(); > if (rt==null) rt = new ResultsTable(); > impProc = IJ.getImage(); > impProc.setRoi(new OvalRoi(405,585,54,57)); > IJ.run("ROI Manager...", ""); > rm.addRoi(impProc.getRoi()); > rm.select(impProc, 0); > ipProc = impProc.getProcessor(); > stats = ipProc.getStatistics(); > mean = stats.mean; > print("The mean is: " + mean); > > stats2 = impProc.getStatistics(); > mean2 = stats.mean; > print("Mean2 is: " + mean2); > > I get the following output: > > The mean is: 49.10071474983756 > Mean2 is: 49.10071474983756 > > However, if I use analyze, measure in the graphical user interface, I get a > mean intensity value of 60.8043. > > > What might the problem be? > > Thanks, > Avital -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you, Wayne! Now I understand how to update the ImageProcessor about
the current selection. For example, if I have ROIs in the ROI manager from an overlay, and I'd like to use the ImageProcessor, I can use the following commands: impProc = IJ.getImage(); // getting the ImagePlus rm.select(selectIndex); // selecting the ROI from the manager selectedRoi = rm.getRoi(selectIndex); // getting the selected ROI //impProc.setRoi(selectedRoi); // Making sure the ImagePlus has the selection. ipProc = impProc.getProcessor(); ipProc.setRoi(selectedRoi); // Making sure the ImageProcessor has the selection. I appreciate your help! Avital On Tue, Aug 25, 2015 at 5:14 PM, Rasband, Wayne (NIH/NIMH) [E] < [hidden email]> wrote: > > > On Aug 24, 2015, at 2:42 PM, Avital Steinberg <[hidden email]> > wrote: > > > > Hi, > > I'm trying to do some measurements using Javascript. When I run the > > following code on the attached image: > > You need to assign the ROI to the ImageProcessor by calling > ImageProcessor.setRoi(). This JavaScript > > img = IJ.getImage(); > roi = new OvalRoi(405,585,54,57); > img.setRoi(roi); > ip = img.getProcessor(); > ip.setRoi(roi); > stats = ip.getStatistics(); > print("The mean is: " + stats.mean); > stats2 = img.getStatistics(); > print("Mean2 is: " + stats2.mean); > > outputs > > The mean is: 60.80429397192403 > Mean2 is: 60.80429397192403 > > If you remove "ip.setRoi(roi);” and run it again you get > > The mean is: 49.10071474983756 > Mean2 is: 60.80429397192403 > > -wayne > > > > importClass(Packages.ij.IJ); > > importClass(Packages.ij.plugin.frame.RoiManager); > > importClass(Packages.ij.io.OpenDialog); > > importClass(Packages.ij.io.DirectoryChooser); > > importClass(Packages.java.io.File); > > importClass(Packages.ij.gui.GenericDialog); > > importClass(Packages.ij.util.Tools); > > importClass(Packages.ij.plugin.Duplicator); > > importClass(Packages.ij.measure.ResultsTable); > > importClass(Packages.ij.ImagePlus); > > importClass(Packages.ij.process.ImageProcessor); > > importClass(Packages.ij.gui.OvalRoi); > > > > IJ = IJ(); > > rm = RoiManager.getInstance(); > > rt = ResultsTable.getResultsTable(); > > if (rm==null) rm = new RoiManager(); > > if (rt==null) rt = new ResultsTable(); > > impProc = IJ.getImage(); > > impProc.setRoi(new OvalRoi(405,585,54,57)); > > IJ.run("ROI Manager...", ""); > > rm.addRoi(impProc.getRoi()); > > rm.select(impProc, 0); > > ipProc = impProc.getProcessor(); > > stats = ipProc.getStatistics(); > > mean = stats.mean; > > print("The mean is: " + mean); > > > > stats2 = impProc.getStatistics(); > > mean2 = stats.mean; > > print("Mean2 is: " + mean2); > > > > I get the following output: > > > > The mean is: 49.10071474983756 > > Mean2 is: 49.10071474983756 > > > > However, if I use analyze, measure in the graphical user interface, I > get a > > mean intensity value of 60.8043. > > > > > > What might the problem be? > > > > Thanks, > > Avital > > -- > 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 |