Login  Register

Re: AnalyzeSkeleton in JavaScript: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

Posted by SarahBerlin on Feb 15, 2016; 3:53pm
URL: http://imagej.273.s1.nabble.com/AnalyzeSkeleton-in-JavaScript-Exception-in-thread-AWT-EventQueue-0-java-lang-NullPointerException-tp5015617p5015637.html

Hi Ignacio.

As you told me works. But unfortunately it does not fufill my needs. My ultimate goal is to read out the AnalyzeSkeleton results from each ROI seperately. When I initialize  AnalyzeSkeleton with the whole image it gives only results for the whole image.
So I now treat every ROI within a loop: first I duplicate the ROI into another imp and then I start AnalyzeSkeleton. But unfortunately again I recieve a nullPointer exception.

Is there a work-around for that?
Thank you in advance.
Sarah

code-snippet:

importPackage(Packages.ij);
importPackage(Packages.ij.plugin);
importPackage(Packages.sc.fiji.analyzeSkeleton);
importClass(Packages.ij.plugin.frame.RoiManager);

var imp1 = IJ.getImage();
var roi_manager = RoiManager.getInstance();
var roi_list    = roi_manager.getRoisAsArray();

for (var roi = 0; roi < 1; roi++) {
        // get current (open) image
        imp1 = IJ.getImage();
        // set ROI with index roi
        imp1.setRoi(roi_list[roi]);

        // duplicate ROI = Image_Plus (image to work on)
        IJ.run("Duplicate...", "name");
        imp = IJ.getImage();

        // Initialize AnalyzeSkeleton_ with grayscale image
        var skel = new AnalyzeSkeleton_();     // works fine
        skel.calculateShortestPath = true;      // causes nullPointer exception
        skel.setup("", imp);                          // causes nullPointer exception


        imp.changes = false;
        imp.close()
       
}

Ignacio Arganda-Carreras-2 wrote
Sorry, Sarah. I was wrong on my remark. As nicely pointed out by Richard
Domander, the fourth parameter of that run method is not input skeleton
image but the original grayscale image (for lowest pixel intensity pruning
mode). So setting to null is fine. What you need to do is to call setup
with the input image before calling run, or the plugin will crash with a
NullPointerException.

Best,

ignacio