Hi,
I wrote some scripts a long time ago and now they stopped working, although I didn't change them. I discovered that there's a bug, in which the median value which is measured is always equal to zero: (but if I measure it with the gui it gives the right median value) importClass(Packages.ij.IJ); importClass(Packages.ij.plugin.frame.RoiManager); importClass(Packages.ij.ImagePlus); importClass(Packages.ij.process.ImageProcessor); importClass(Packages.ij.gui.Roi); importClass(Packages.ij.gui.OvalRoi); importClass(Packages.ij.process.ImageStatistics); rm = RoiManager.getInstance(); if (rm==null) rm = new RoiManager(); imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); imp.setRoi(new OvalRoi(471,273,177,180)); imp.show(); IJ.run("ROI Manager...", ""); rm.addRoi(imp.getRoi()); rm.select(0); ip = imp.getProcessor(); selROI = rm.getRoi(0); imp.setRoi(selROI, false); ip.setRoi(selROI); stats = ip.getStatistics(); median = stats.median; // Adjusted median IJ.log("The median is: " + median); Other Imagestatistics values such as the area are fine. I'm using Imagej 1.51i2 with Java 1.6.0_65, because all my scripts were written with Javascript and Rhino (not Nashorn), so they don't work with Java 8. Can you regenerate the bug? Any idea how to fix it? Thanks, Avital -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good day Avital
when running your script entered to a window from "Plugins > New > JavaScript" I get in the Log-window: "The median is: 71" ImageJ 1.51h, OSX 10.11.6, 64bit Java 1.6.0_65. HTH Herbie :::::::::::::::::::::::::::::::::::::::::::::: Am 27.11.16 um 15:57 schrieb Avital Steinberg: > importClass(Packages.ij.IJ); > importClass(Packages.ij.plugin.frame.RoiManager); > importClass(Packages.ij.ImagePlus); > importClass(Packages.ij.process.ImageProcessor); > importClass(Packages.ij.gui.Roi); > importClass(Packages.ij.gui.OvalRoi); > importClass(Packages.ij.process.ImageStatistics); > > rm = RoiManager.getInstance(); > if (rm==null) rm = new RoiManager(); > > imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); > imp.setRoi(new OvalRoi(471,273,177,180)); > imp.show(); > IJ.run("ROI Manager...", ""); > rm.addRoi(imp.getRoi()); > rm.select(0); > ip = imp.getProcessor(); > selROI = rm.getRoi(0); > imp.setRoi(selROI, false); > ip.setRoi(selROI); > stats = ip.getStatistics(); > median = stats.median; // Adjusted median > IJ.log("The median is: " + median); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks, Herbie - when I run it with Fiji on my Linux machine, which has
ImageJ 1.51a13 with Java 1.6.0_24, there is no bug like you said. But when I run it on Fiji with my 10.9.5 mac OsX, I get a value of zero. Can anyone else reproduce the bug? Thanks, Avital On Sun, Nov 27, 2016 at 5:20 PM, Herbie <[hidden email]> wrote: > Good day Avital > > when running your script entered to a window from "Plugins > New > > JavaScript" I get in the Log-window: > > "The median is: 71" > > ImageJ 1.51h, OSX 10.11.6, 64bit Java 1.6.0_65. > > HTH > > Herbie > > :::::::::::::::::::::::::::::::::::::::::::::: > Am 27.11.16 um 15:57 schrieb Avital Steinberg: > >> importClass(Packages.ij.IJ); >> importClass(Packages.ij.plugin.frame.RoiManager); >> importClass(Packages.ij.ImagePlus); >> importClass(Packages.ij.process.ImageProcessor); >> importClass(Packages.ij.gui.Roi); >> importClass(Packages.ij.gui.OvalRoi); >> importClass(Packages.ij.process.ImageStatistics); >> >> rm = RoiManager.getInstance(); >> if (rm==null) rm = new RoiManager(); >> >> imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); >> imp.setRoi(new OvalRoi(471,273,177,180)); >> imp.show(); >> IJ.run("ROI Manager...", ""); >> rm.addRoi(imp.getRoi()); >> rm.select(0); >> ip = imp.getProcessor(); >> selROI = rm.getRoi(0); >> imp.setRoi(selROI, false); >> ip.setRoi(selROI); >> stats = ip.getStatistics(); >> median = stats.median; // Adjusted median >> IJ.log("The median is: " + median); >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good afternoon Avital,
I've just upgraded ImageJ to the daily build 1.51i and now I can confirm median = 0. This seems to be a case for Wayne... Best Herbie ::::::::::::::::::::::::::::::::::::::::::::: Am 27.11.16 um 16:35 schrieb Avital Steinberg: > Thanks, Herbie - when I run it with Fiji on my Linux machine, which has > ImageJ 1.51a13 with Java 1.6.0_24, there is no bug like you said. But when > I run it on Fiji with my 10.9.5 mac OsX, I get a value of zero. > > Can anyone else reproduce the bug? > Thanks, > Avital > > On Sun, Nov 27, 2016 at 5:20 PM, Herbie <[hidden email]> wrote: > >> Good day Avital >> >> when running your script entered to a window from "Plugins > New > >> JavaScript" I get in the Log-window: >> >> "The median is: 71" >> >> ImageJ 1.51h, OSX 10.11.6, 64bit Java 1.6.0_65. >> >> HTH >> >> Herbie >> >> :::::::::::::::::::::::::::::::::::::::::::::: >> Am 27.11.16 um 15:57 schrieb Avital Steinberg: >> >>> importClass(Packages.ij.IJ); >>> importClass(Packages.ij.plugin.frame.RoiManager); >>> importClass(Packages.ij.ImagePlus); >>> importClass(Packages.ij.process.ImageProcessor); >>> importClass(Packages.ij.gui.Roi); >>> importClass(Packages.ij.gui.OvalRoi); >>> importClass(Packages.ij.process.ImageStatistics); >>> >>> rm = RoiManager.getInstance(); >>> if (rm==null) rm = new RoiManager(); >>> >>> imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); >>> imp.setRoi(new OvalRoi(471,273,177,180)); >>> imp.show(); >>> IJ.run("ROI Manager...", ""); >>> rm.addRoi(imp.getRoi()); >>> rm.select(0); >>> ip = imp.getProcessor(); >>> selROI = rm.getRoi(0); >>> imp.setRoi(selROI, false); >>> ip.setRoi(selROI); >>> stats = ip.getStatistics(); >>> median = stats.median; // Adjusted median >>> IJ.log("The median is: " + median); >>> >> >> -- >> 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 |
On Sunday, 27 November 2016 16:57:08 GMT Herbie wrote:
> I've just upgraded ImageJ to the daily build 1.51i and now I can confirm > median = 0. Hi, Yes, I can confirm this under java 6 (same version as yours) and 8 (1.8.0_66) under linux 64. But what I noted also is that if you press M after your script, the results table does show the right value of 71 (if you have selected it in the Set Measurements). Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Herbie
I can reproduce it, but I dont think that it is a bug.
ip.getStatistics() does nto claim to return the median. Here is the API doc: Calculates and returns statistics (area, mean, std-dev, mode, min, max, centroid, center of mass, 256 bin histogram) for this image or ROI. ImageStatistics.getStatistics() is: public staticImageStatistics <https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html> getStatistics(ImageProcessor <https://imagej.nih.gov/ij/developer/api/ij/process/ImageProcessor.html> ip, int mOptions, Calibration <https://imagej.nih.gov/ij/developer/api/ij/measure/Calibration.html> cal) If you set mOptions, you can get it to return many other things (including median), but I dont know how to set mOptions. Where is that documented? I think if you use the ImageStatistics.getStatistics() with the correct mOptions, you will get the median. --aryeh On 27/11/2016 17:57, Herbie wrote: > Good afternoon Avital, > > I've just upgraded ImageJ to the daily build 1.51i and now I can > confirm median = 0. > > This seems to be a case for Wayne... > > Best > > Herbie > > ::::::::::::::::::::::::::::::::::::::::::::: > Am 27.11.16 um 16:35 schrieb Avital Steinberg: >> Thanks, Herbie - when I run it with Fiji on my Linux machine, which has >> ImageJ 1.51a13 with Java 1.6.0_24, there is no bug like you said. But >> when >> I run it on Fiji with my 10.9.5 mac OsX, I get a value of zero. >> >> Can anyone else reproduce the bug? >> Thanks, >> Avital >> >> On Sun, Nov 27, 2016 at 5:20 PM, Herbie <[hidden email]> wrote: >> >>> Good day Avital >>> >>> when running your script entered to a window from "Plugins > New > >>> JavaScript" I get in the Log-window: >>> >>> "The median is: 71" >>> >>> ImageJ 1.51h, OSX 10.11.6, 64bit Java 1.6.0_65. >>> >>> HTH >>> >>> Herbie >>> >>> :::::::::::::::::::::::::::::::::::::::::::::: >>> Am 27.11.16 um 15:57 schrieb Avital Steinberg: >>> >>>> importClass(Packages.ij.IJ); >>>> importClass(Packages.ij.plugin.frame.RoiManager); >>>> importClass(Packages.ij.ImagePlus); >>>> importClass(Packages.ij.process.ImageProcessor); >>>> importClass(Packages.ij.gui.Roi); >>>> importClass(Packages.ij.gui.OvalRoi); >>>> importClass(Packages.ij.process.ImageStatistics); >>>> >>>> rm = RoiManager.getInstance(); >>>> if (rm==null) rm = new RoiManager(); >>>> >>>> imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); >>>> imp.setRoi(new OvalRoi(471,273,177,180)); >>>> imp.show(); >>>> IJ.run("ROI Manager...", ""); >>>> rm.addRoi(imp.getRoi()); >>>> rm.select(0); >>>> ip = imp.getProcessor(); >>>> selROI = rm.getRoi(0); >>>> imp.setRoi(selROI, false); >>>> ip.setRoi(selROI); >>>> stats = ip.getStatistics(); >>>> median = stats.median; // Adjusted median >>>> IJ.log("The median is: " + median); >>>> >>> >>> -- >>> 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 > -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear all,
the Median calculation was recently removed from both ImagePlus [1] and ImageStatistics [2] by Wayne in reaction to a related bug report [3]. I guess that from v1.51i on, you'll have to use .getAllStatistics() introduced with v1.51i2 [4] instead of .getStatistics(). This is a backwards-incompatible change, but as mentioned in the github issue, this improved the performance of the Brightness&Contrast dialog. Hope that helps, Jan [1]: https://github.com/imagej/imagej1/commit/6e74324174a6c5c87bd01c1a9ffb5568de8b1dce [2]: https://github.com/imagej/imagej1/commit/354b0d50a9f4c34908c0cb573d05ecde69ad5052 [3]: https://github.com/imagej/imagej1/issues/25#issuecomment-261691787 [4]: https://github.com/imagej/imagej1/commit/6e74324174a6c5c87bd01c1a9ffb5568de8b1dce On 27.11.16 17:10, Aryeh Weiss wrote: > I can reproduce it, but I dont think that it is a bug. > > ip.getStatistics() does nto claim to return the median. > Here is the API doc: > Calculates and returns statistics (area, mean, std-dev, mode, min, max, > centroid, center of mass, 256 bin histogram) for this image or ROI. > > ImageStatistics.getStatistics() is: > > public staticImageStatistics > <https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html> > getStatistics(ImageProcessor > <https://imagej.nih.gov/ij/developer/api/ij/process/ImageProcessor.html> ip, > > int mOptions, > Calibration > <https://imagej.nih.gov/ij/developer/api/ij/measure/Calibration.html> cal) > > If you set mOptions, you can get it to return many other things > (including median), but I dont know how to set mOptions. > Where is that documented? > > I think if you use the ImageStatistics.getStatistics() > with the correct mOptions, you will get the median. > > --aryeh > > On 27/11/2016 17:57, Herbie wrote: >> Good afternoon Avital, >> >> I've just upgraded ImageJ to the daily build 1.51i and now I can >> confirm median = 0. >> >> This seems to be a case for Wayne... >> >> Best >> >> Herbie >> >> ::::::::::::::::::::::::::::::::::::::::::::: >> Am 27.11.16 um 16:35 schrieb Avital Steinberg: >>> Thanks, Herbie - when I run it with Fiji on my Linux machine, which has >>> ImageJ 1.51a13 with Java 1.6.0_24, there is no bug like you said. But >>> when >>> I run it on Fiji with my 10.9.5 mac OsX, I get a value of zero. >>> >>> Can anyone else reproduce the bug? >>> Thanks, >>> Avital >>> >>> On Sun, Nov 27, 2016 at 5:20 PM, Herbie <[hidden email]> wrote: >>> >>>> Good day Avital >>>> >>>> when running your script entered to a window from "Plugins > New > >>>> JavaScript" I get in the Log-window: >>>> >>>> "The median is: 71" >>>> >>>> ImageJ 1.51h, OSX 10.11.6, 64bit Java 1.6.0_65. >>>> >>>> HTH >>>> >>>> Herbie >>>> >>>> :::::::::::::::::::::::::::::::::::::::::::::: >>>> Am 27.11.16 um 15:57 schrieb Avital Steinberg: >>>> >>>>> importClass(Packages.ij.IJ); >>>>> importClass(Packages.ij.plugin.frame.RoiManager); >>>>> importClass(Packages.ij.ImagePlus); >>>>> importClass(Packages.ij.process.ImageProcessor); >>>>> importClass(Packages.ij.gui.Roi); >>>>> importClass(Packages.ij.gui.OvalRoi); >>>>> importClass(Packages.ij.process.ImageStatistics); >>>>> >>>>> rm = RoiManager.getInstance(); >>>>> if (rm==null) rm = new RoiManager(); >>>>> >>>>> imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); >>>>> imp.setRoi(new OvalRoi(471,273,177,180)); >>>>> imp.show(); >>>>> IJ.run("ROI Manager...", ""); >>>>> rm.addRoi(imp.getRoi()); >>>>> rm.select(0); >>>>> ip = imp.getProcessor(); >>>>> selROI = rm.getRoi(0); >>>>> imp.setRoi(selROI, false); >>>>> ip.setRoi(selROI); >>>>> stats = ip.getStatistics(); >>>>> median = stats.median; // Adjusted median >>>>> IJ.log("The median is: " + median); >>>>> >>>> >>>> -- >>>> 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 >> > > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
The bad news is that this issue applies not only to the median but also for
some other ImageStatistics fields. (for example, the xCentroid and xCenterOfMass) <https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html#xCenterOfMass>After I made my own custom function for the median and thought I'd be able to use the same syntax regardless of the version of ImageJ, I discovered that the script is still not working. The good news is that getAllStatistics indeed solves the problem, Avital On Sun, Nov 27, 2016 at 10:00 PM, Avital Steinberg < [hidden email]> wrote: > Thanks Herbie, Gabriel, Aryeh and especially Jan for your help. Now I > understand what's going on because I knew that my script used to work and > suddenly stopped working. Now I know how to fix it, > > Avital > > On Sun, Nov 27, 2016 at 8:32 PM, Jan Eglinger <[hidden email]> > wrote: > >> Dear all, >> >> the Median calculation was recently removed from both ImagePlus [1] and >> ImageStatistics [2] by Wayne in reaction to a related bug report [3]. >> >> I guess that from v1.51i on, you'll have to use .getAllStatistics() >> introduced with v1.51i2 [4] instead of .getStatistics(). >> >> This is a backwards-incompatible change, but as mentioned in the github >> issue, this improved the performance of the Brightness&Contrast dialog. >> >> Hope that helps, >> Jan >> >> >> [1]: https://github.com/imagej/imagej1/commit/6e74324174a6c5c87bd >> 01c1a9ffb5568de8b1dce >> [2]: https://github.com/imagej/imagej1/commit/354b0d50a9f4c34908c >> 0cb573d05ecde69ad5052 >> [3]: https://github.com/imagej/imagej1/issues/25#issuecomment-261691787 >> [4]: https://github.com/imagej/imagej1/commit/6e74324174a6c5c87bd >> 01c1a9ffb5568de8b1dce >> >> >> >> On 27.11.16 17:10, Aryeh Weiss wrote: >> >>> I can reproduce it, but I dont think that it is a bug. >>> >>> ip.getStatistics() does nto claim to return the median. >>> Here is the API doc: >>> Calculates and returns statistics (area, mean, std-dev, mode, min, max, >>> centroid, center of mass, 256 bin histogram) for this image or ROI. >>> >>> ImageStatistics.getStatistics() is: >>> >>> public staticImageStatistics >>> <https://imagej.nih.gov/ij/developer/api/ij/process/ImageStatistics.html >>> > >>> getStatistics(ImageProcessor >>> <https://imagej.nih.gov/ij/developer/api/ij/process/ImageProcessor.html> >>> ip, >>> >>> int mOptions, >>> Calibration >>> <https://imagej.nih.gov/ij/developer/api/ij/measure/Calibration.html> >>> cal) >>> >>> >>> If you set mOptions, you can get it to return many other things >>> (including median), but I dont know how to set mOptions. >>> Where is that documented? >>> >>> I think if you use the ImageStatistics.getStatistics() >>> with the correct mOptions, you will get the median. >>> >>> --aryeh >>> >>> On 27/11/2016 17:57, Herbie wrote: >>> >>>> Good afternoon Avital, >>>> >>>> I've just upgraded ImageJ to the daily build 1.51i and now I can >>>> confirm median = 0. >>>> >>>> This seems to be a case for Wayne... >>>> >>>> Best >>>> >>>> Herbie >>>> >>>> ::::::::::::::::::::::::::::::::::::::::::::: >>>> Am 27.11.16 um 16:35 schrieb Avital Steinberg: >>>> >>>>> Thanks, Herbie - when I run it with Fiji on my Linux machine, which has >>>>> ImageJ 1.51a13 with Java 1.6.0_24, there is no bug like you said. But >>>>> when >>>>> I run it on Fiji with my 10.9.5 mac OsX, I get a value of zero. >>>>> >>>>> Can anyone else reproduce the bug? >>>>> Thanks, >>>>> Avital >>>>> >>>>> On Sun, Nov 27, 2016 at 5:20 PM, Herbie <[hidden email]> wrote: >>>>> >>>>> Good day Avital >>>>>> >>>>>> when running your script entered to a window from "Plugins > New > >>>>>> JavaScript" I get in the Log-window: >>>>>> >>>>>> "The median is: 71" >>>>>> >>>>>> ImageJ 1.51h, OSX 10.11.6, 64bit Java 1.6.0_65. >>>>>> >>>>>> HTH >>>>>> >>>>>> Herbie >>>>>> >>>>>> :::::::::::::::::::::::::::::::::::::::::::::: >>>>>> Am 27.11.16 um 15:57 schrieb Avital Steinberg: >>>>>> >>>>>> importClass(Packages.ij.IJ); >>>>>>> importClass(Packages.ij.plugin.frame.RoiManager); >>>>>>> importClass(Packages.ij.ImagePlus); >>>>>>> importClass(Packages.ij.process.ImageProcessor); >>>>>>> importClass(Packages.ij.gui.Roi); >>>>>>> importClass(Packages.ij.gui.OvalRoi); >>>>>>> importClass(Packages.ij.process.ImageStatistics); >>>>>>> >>>>>>> rm = RoiManager.getInstance(); >>>>>>> if (rm==null) rm = new RoiManager(); >>>>>>> >>>>>>> imp = IJ.createImage("randRamp", "8-bit ramp", 2000, 2048, 1); >>>>>>> imp.setRoi(new OvalRoi(471,273,177,180)); >>>>>>> imp.show(); >>>>>>> IJ.run("ROI Manager...", ""); >>>>>>> rm.addRoi(imp.getRoi()); >>>>>>> rm.select(0); >>>>>>> ip = imp.getProcessor(); >>>>>>> selROI = rm.getRoi(0); >>>>>>> imp.setRoi(selROI, false); >>>>>>> ip.setRoi(selROI); >>>>>>> stats = ip.getStatistics(); >>>>>>> median = stats.median; // Adjusted median >>>>>>> IJ.log("The median is: " + median); >>>>>>> >>>>>>> >>>>>> -- >>>>>> 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 >>>> >>>> >>> >>> > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |