Null Pointer Exception in Particle Analyser

The attached binary stack (containing one particle) raises a null pointer exception (with many array index out of bounds exceptions in the console window) when I run the Particle Analyser. For example:

run(“Particle Analyser”, " min=0.000 max=Infinity surface_resampling=2 surface=Gradient split=0.000 volume_resampling=2");

If I remove the first slice, it runs without any problems. This is just a sample - I’m having the problem with other larger stacks, in a pattern I can’t discern.

Everything is up to date in Fiji. Same result on two computers (Windows 7 and 10). Any help would be appreciated. Thanks.

NP_exception.zip (3.1 KB)

(Fiji Is Just) ImageJ 2.0.0-rc-69/1.52p; Java 1.8.0_172 [64-bit];

I can confirm. Exception message is this:

(Fiji Is Just) ImageJ 2.0.0-rc-71/1.52p; Java 1.8.0_172 [64-bit]; Linux 4.4.0-179-generic; 596MB of 128000MB (<1%)
 
java.lang.NullPointerException
	at org.bonej.plugins.ParticleAnalysis.getParticleSizes(ParticleAnalysis.java:311)
	at org.bonej.plugins.ParticleAnalysis.filterParticles(ParticleAnalysis.java:113)
	at org.bonej.plugins.ParticleCounter.getParticles(ParticleCounter.java:493)
	at org.bonej.plugins.ParticleCounter.run(ParticleCounter.java:229)
	at ij.IJ.runUserPlugIn(IJ.java:230)
	at ij.IJ.runPlugIn(IJ.java:193)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at ij.IJ.run(IJ.java:312)
	at ij.IJ.run(IJ.java:323)
	at ij.macro.Functions.doRun(Functions.java:624)
	at ij.macro.Functions.doFunction(Functions.java:97)
	at ij.macro.Interpreter.doStatement(Interpreter.java:275)
	at ij.macro.Interpreter.doStatements(Interpreter.java:261)
	at ij.macro.Interpreter.run(Interpreter.java:157)
	at ij.macro.Interpreter.run(Interpreter.java:91)
	at ij.macro.Interpreter.run(Interpreter.java:102)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.IJ.runMacro(IJ.java:148)
	at ij.IJ.runMacro(IJ.java:137)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1148)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1144)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1095)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1144)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:145)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

This is a super weird bug. Thank you for reporting it. Please keep an eye on this report: https://github.com/bonej-org/BoneJ2/issues/261

At first it looked like a straightforward out-by-one and not checking for null type of bug. But it’s curious because it goes away if more than one particle is present; if the single particle is at the top of the stack rather than the bottom (Image > Stacks > Tools > Reverse).

Do the other stacks you are working with have a similar layout, of a single particle at the bottom (high z value) of the stack?

Thanks for looking at this.
Actually, so far its with different parts of the same stack, with particles scattered throughout. I have attached the whole stack. You should find, for example, that 1186-1202 works (2 particles) but 1185-1202 and 1186-1201 don`t.
1106-1810 (29 particles) behaves similarly.
The piece I sent previously was 1186-1196.

160_mask.zip (711.8 KB)

1 Like

Seems like there are multiple issues here, relating to empty slices and keeping count of particles vs. array lengths that is exposed by these sparsely populated images. This situation should be handled gracefully, but while you’re waiting for a bug fix you can do something like the following prior to running Particle Analyser:

setForegroundColor(255, 255, 255);
run("Specify...", "width=10 height=10 x=0 y=0 slice=1");
run("Fill", "stack");
run("Select None");

This adds a particle to the top left corner that passes through all slices of the stack, working for your kinds of images which are empty outside the central cylinder. The fake particle should be assigned label 1.0 (check by hovering your cursor on the label image) and have a volume of nSlices × 100 pixels, so you can find and ignore it in later analysis.

This should be fixed once the PR below is merged and released, over the next few days. Let your updater run.


@mjlondon, thanks for the report and the test images, they really helped to narrow down the root cause.

Thanks for all your help. The workaround works just fine for me.

1 Like

I received the update and it works perfectly. Great job. Thanks.

1 Like