Login  Register

Re: How to construct the ROI manager

Posted by Olivier Burri on Aug 24, 2015; 12:54pm
URL: http://imagej.273.s1.nabble.com/How-to-construct-the-ROI-manager-tp5014113p5014126.html

Hello,

That nullpointer seems to stem from the fact that the Roi Manager might be emptz or uninitialized

I'd suggest you add this at the beginning to make sure that this is not the problem

If(returnedRM == null) {
        IJ.error("No RoiManager!");
        // Or you could instantiate a new RoiManager
        returnedRM = new RoiManager();
}

But your script seems to be run after the RoiManager is populated so this should not happen.

Best

Oli

> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> Jan Eglinger
> Sent: Sunday, August 23, 2015 18:34
> To: [hidden email]
> Subject: Re: How to construct the ROI manager
>
> Hi Avital,
>
>  > rm = RoiManager();
>  > returnedRm = rm.getInstance();
>
> getInstance is a _static_ method of the RoiManager class, i.e. you don't need
> to create an instance of RoiManager, just call the method like this:
>
>      rm = RoiManager.getInstance()
>
> See also here:
> http://fiji.sc/Scripting_toolbox#Select_multiple_ROIs_from_ROI_manager_a
> nd_combine_them
>
> Hope that helps,
> Jan
>
>
> On 23.08.15 11:04, Avital Steinberg wrote:
> > Hi,
> > I'm trying to count the number of objects in the roi manager in Javascript.
> > I wrote the following code:
> >
> > 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);
> >
> > IJ = IJ();
> > rm = RoiManager();
> > returnedRm = rm.getInstance();
> > print("The returned rm is: " + returnedRm); var nObjects =
> > rm.getCount(); print("nObjects is: " + nObjects);
> >
> > And I get the following error message:
> >
> > javax.script.ScriptException:
> > sun.org.mozilla.javascript.internal.WrappedException: Wrapped
> > java.lang.NullPointerException
> >
> > When I comment out the problematic line (var nObjects =
> > rm.getCount();) I get the following Roi Manager type for the rm:
> > (getInstance returned this)
> >
> > The returned rm is:
> > ij.plugin.frame.RoiManager[frame61,884,327,240x330,invalid,layout=java
> > .awt.BorderLayout,title=ROI
> > Manager,resizable,normal]
> >
> > How would I count the number of ROIs in the Roi manager? And how can I
> > use the RoiManager class methods?
> >
> > Thanks,
> > Avital
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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