help with PartlcleAnalyzer.analyzeParticle and ADD_TO_MANAGER

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

help with PartlcleAnalyzer.analyzeParticle and ADD_TO_MANAGER

Julin Maloof
Hello,

I am trying to use the ParticleAnalyzer on a specific ROI and then have particles added to the ROI Manager.  I get a runtime exception:

java.lang.NullPointerException
        at ij.plugin.frame.RoiManager.getLabel(RoiManager.java:266)
        at ij.plugin.frame.RoiManager.add(RoiManager.java:226)
        at ij.plugin.filter.ParticleAnalyzer.saveResults(ParticleAnalyzer.java:669)
        at ij.plugin.filter.ParticleAnalyzer.analyzeParticle(ParticleAnalyzer.java:621)
        at ij.plugin.filter.ParticleAnalyzer.analyze(ParticleAnalyzer.java:408)
        at hypocotyl.addToManager(hypocotyl.java:138)
        at hyp_multi.run(hyp_multi.java:83)
        at ij.IJ.runFilterPlugIn(IJ.java:200)
        at ij.IJ.runUserPlugIn(IJ.java:268)
        at ij.ImageJ.runUserPlugIn(ImageJ.java:212)
        at ij.plugin.PlugInExecuter.run(Compiler.java:188)
        at java.lang.Thread.run(Thread.java:613)

This only happens if I have the ADD_TO_MANAGER flag set.  Otherwise particles within the ROI can be found.  The final code where the exception occurs (RoiManager.java:266) is

        if (imp.getStackSize()>1) {

Suggesting that imp is not pointing to anything(?)

I am little mystified because if I insert

        IJ.write("test"+IJ.d2s(imp.getStackSize()));

in my code just before ParticleAnalyzer.analyzeParticles is called it works.  So why is the reference being lost?  Any suggestions?  My method where this occurs follow.  Thanks in advance, Julin

        public void addToManager(ImagePlus imp, ImageProcessor ip, RoiManager rm){
                //use Analyze Particles to find Hypocotyl within an ROI

                ResultsTable rt = new ResultsTable();
                ParticleAnalyzer pa = new ParticleAnalyzer(ParticleAnalyzer.ADD_TO_MANAGER+
                         ParticleAnalyzer.RECORD_STARTS,
                        Measurements.FERET, rt, 100, Double.POSITIVE_INFINITY);
                //If I remove "ParticleAnalyzer.ADD_TO_MANAGER" from above, no error occurs

               
                //define the ROI
                int[] tmpx = {(int) Math.round(topLine[0]),(int) Math.round(topLine[2]),
                        (int) Math.round(bottomLine[2]),(int) Math.round(bottomLine[0])};
                int[] tmpy = {(int) Math.round(topLine[1]),(int) Math.round(topLine[3]),
                        (int) Math.round(bottomLine[3]),(int) Math.round(bottomLine[1])};
                PolygonRoi roi = new PolygonRoi(tmpx,tmpy,4,Roi.POLYGON);
               

                imp.setRoi(roi);
                ip.threshold((int) Math.round(ip.getAutoThreshold()*1.25)); //required for particle analyzer
                IJ.write("test"+IJ.d2s(imp.getStackSize())); //works
                pa.analyze(imp, ip); //error occurs here
                imp.updateAndDraw();
        }





--
Julin Maloof
Assistant Professor
Section of Plant Biology
University of California, Davis
1 Shields Ave
Davis, CA, 95616

voice: (530) 752-8077
fax:   (530) 752-5410