BioVoxxel Extended Particle Analyzer fails without shown image. Possible to script via API?

Dear @biovoxxel,

I am using the Extended Particle Analyzer (EPA) from your awesome toolbox in a jython script, but ran into an issue. I believe that it only actually works if an image is shown. It also does not actually matter which image is shown . You can reproduce the issue like this:

from ij import IJ

imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif")
# imp.show() # uncomment this line to make EPA work again
imp2 = imp.duplicate()
IJ.run(imp2, "Auto Threshold", "method=Default")
IJ.run(imp2, "Invert", "")
IJ.run(imp2, "Extended Particle Analyzer", "pixel area=0-5000 show=Nothing redirect=None keep=None add");

the error message is the following:

(Fiji Is Just) ImageJ 2.0.0-rc-69/1.51w; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 260MB of 32000MB (<1%)
 
java.lang.NullPointerException
	at de.biovoxxel.toolbox.Extended_Particle_Analyzer.getImageNames(Extended_Particle_Analyzer.java:814)
	at de.biovoxxel.toolbox.Extended_Particle_Analyzer.readInputImageParameters(Extended_Particle_Analyzer.java:374)
	at de.biovoxxel.toolbox.Extended_Particle_Analyzer.run(Extended_Particle_Analyzer.java:133)
	at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:265)
	at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
	at ij.IJ.runUserPlugIn(IJ.java:223)
	at ij.IJ.runPlugIn(IJ.java:185)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:63)
	at ij.IJ.run(IJ.java:301)
	at ij.IJ.run(IJ.java:357)
	at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
	at org.python.core.PyObject.__call__(PyObject.java:515)
	at org.python.core.PyObject.__call__(PyObject.java:519)
	at org.python.pycode._pyx40.f$0(Untitled.ijm.py:10)
	at org.python.pycode._pyx40.call_function(Untitled.ijm.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	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)

My gut feeling is that EPA wants to grab the front window to do something with it, but as there is no shown window this fails.
Is there maybe a way around this issue, for example by scripting EPA directly, and not via IJ.run(…?

I found the EPA-java code on github, but unfortunately I am not advanced enough to address it in a jython script.
Thank you for your help!

Hi @CellKai,

I can reproduce the problem and I guess your gut feeling is right. The method the error points to uses ImageJ’s WindowManager to read image names and that might be working only for displayed images. I created the EPA in the beginnings of my programming experience and it surely has some flaws. I think @aryeh once had a similar problem and due to that I added some changes which circumvent the non-scriptablility of the EPA and should make that possible .

Please try the following… (it is not python, but I guess you will be able to adapt it accordingly.

Extended_Particle_Analyzer epa = new Extended_Particle_Analyzer();
epa.readInputImageParameters(imp);
epa.setDefaultParameterFields();
epa.defineParticleAnalyzers();
epa.particleAnalysis(imp.getProcessor(), imp, "blah");

If you want to adapt parameters you can do it individually AFTER the setDefaultParameterFields(); method using the object and the corresponding parameter e.g. epa.AR=“1.0-4.0” OR epa.Area=“100-Infinity”;

The first 3 methods define all necessary parameters to run the EPA with default parameters and cannot be omitted. please let me know if that somehow works for you.

3 Likes

Hi @biovoxxel,

thank you so much for the quick reply and sorry for the slow response!

I got it partially working already :smiley:, but I have a follow-up question:

How do I set the checkboxes?

please see how far I got from the code below:

#@ ImagePlus imp
from de.biovoxxel.toolbox import Extended_Particle_Analyzer

epa = Extended_Particle_Analyzer()
epa.readInputImageParameters(imp)
epa.setDefaultParameterFields()
# adapt parameters here
epa.AR="1.0-4.0"
epa.Area="1.0-Infinity"
# epa.CB3 = True # thats not how to set the checkboxes
epa.defineParticleAnalyzers()
epa.particleAnalysis( imp.getProcessor(), imp, imp.getTitle() )

Thank you for your help!

1 Like

Hi @CellKai,

No access currently to github. But you can find it around line 990. Or at line 100 all the valiables are listed there.

So e.g. epa.DisplayResults=true; should work

Hi @biovoxxel,
thanks so much! it works perfect for me :slight_smile:

1 Like