Calling a pre-existing plugin into a custom script? Binary Feature Extractor (Biovoxxel)

imagej
plugin
biovoxxel

#1

I’d like to use an existing plugin, Binary Feature Extractor (from Biovoxxel), in my custom jython script. I’m having trouble defining the parameters.

I can get the plugin to run fine if I manually input the image titles, obj.tif and sel.tif
IJ.run("Binary Feature Extractor", "objects=obj.tif selector=sel.tif object_overlap=50 combine count")

BUT, since the user will not be able to adjust the code themselves, I’d like the script to input the correct file parameters based on a variable or image title.

I’ve tried to create these variables with:

file1 = "C:/obj.tif"
file2 = "C:/sel.tif"

my_obj = ImagePlus.getTitle(IJ.openImage(file1))
my_sel = ImagePlus.getTitle(IJ.openImage(file2))
print "my_obj=", my_obj 
print "my_sel=", my_sel

which prints

my_obj = obj.tif
my_sel = sel.tif

So I know I’m grabbing the correct Image Titles.

But when I try to put these variables into the run command:
IJ.run("Binary Feature Extractor", "objects=my_obj selector=my_sel object_overlap=50 combine count")

I get the following errors:

(Fiji Is Just) ImageJ 2.0.0-rc-65/1.51w; Java 1.8.0_66 [64-bit]; Windows 10 10.0; 1409MB of 6080MB (23%)

java.lang.NullPointerException
at Binary_Feature_Extractor.run(Binary_Feature_Extractor.java:92)
at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:265)
at ij.plugin.filter.PlugInFilterRunner.(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:66)
at ij.IJ.run(IJ.java:301)
at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:186)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:204)
at org.python.core.PyObject.call(PyObject.java:478)
at org.python.core.PyObject.call(PyObject.java:482)
at org.python.pycode._pyx509.f$0(C:\jjhelp.py:107)
at org.python.pycode._pyx509.call_function(C:\jjhelp.py)
at org.python.core.PyTableCode.call(PyTableCode.java:167)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1386)
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:40)
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$3.call(DefaultThreadService.java:238)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

What should I do to fix this?


#2

Hi @sjeschonek,

without being familiar with jython, I would guess that you need to specify the line different in your script to ensure that it takes image names as variables. This most likely works:

IJ.run("Binary Feature Extractor", "objects="+my_obj+" selector="+my_sel+" object_overlap=50 combine count")

#3

Yep, this works! Thanks!