Run plugin from java/scala program



Hi! I can’t understand where should be a fiji plugin in my project. If I put a plugin in the root plugins folder I got for, "Auto Local Threshold", "method=Phansalkar")

exception: Plugin or class not found “fiji.threashold.Auto_Local_Threashold” … . Ok, I put it with ImageJ jars and got the other: Unrecognized command: Auto Local Threashold . Why? How to fix? is it possible to get direct access (through interface) to it?

P/S. I use attached ImageJ jars rc46 from the site .


Hi @Claus1 and welcome to the forum!

How are you trying to start your plugin? From an IDE like Eclipse or IntelliJ via a main() method? If so, please have a look at the following topics discussing how to add the plugins.dir to your ImageJ instance:

Here’s how the example-legacy-plugin sets the plugins.dir property:

Hope that helps. If not, please don’t hesitate to reply back with some details on what you’ve tried so far.


From the script editor, the following Scala script (using a script parameter in the first line) worked for me:

#@ ImagePlus inputimage

import ij.IJ
import ij.ImagePlus[ImagePlus], "Auto Local Threshold", "method=Phansalkar")

Note that I had to add inputimage.asInstanceOf[ImagePlus], since simply putting inputimage would give me the following error:

javax.script.ScriptException: type mismatch;
 found   : Object
 required: ij.ImagePlus in 

import ij.IJ
import ij.ImagePlus, "Auto Local Threshold", "method=Phansalkar")
 at line number 22 at column number 15

… which is a bit odd. I suspect this might be a bug in scripting-scala, but I do not know enough Scala to judge this.


Scripting inside Fiji works for me as well. But in my program ImageJ refuse to load/execute fiji plugin.
I tried System.getProperties().setProperty(“plugins.dir”, “C:/MyProjects/_visca/plugins”)
System.getProperties().setProperty(“plugins.dir”, “plugins”). It doesn’t help. Class or jar not found message.
And weird how it knows that the plug from fiji (see error message) if it does not see it. In ImageJ jars folder (/lib in my case) it sees the plugin but do not execute command. Why? I do not need the plugin in menu, I need only to use it in my program. Someone can use Auto Local Threshold plugin from java program? Where it should be?


I tried to understand where is the problem inside ImageJ but failed. It sees my plugin folder and saves it in scriptService.ScriptDirectory. But class PluginClassLoader that has to analyze and add is not called at all (?!). Why it is not called is a big question.


@Claus1 Are you sure you need to use ImageJ1-style plugins from your scripts? Some things are already available as SciJava-style plugins (e.g. ImageJ Ops) instead. Then you do not need to suffer through that plugins.dir pain. For example, ImageJ Ops has local thresholding algorithms; see this tutorial notebook.


Yes, it is a bug, already fixed by @keithschulze!

Keith: I am sorry I did not merge and release this yet. I have not forgotten, though.


I ll check ops but it is not problem to use the plug like a regular jar. May be even better. The problem now is a unwelcome logging window :slight_smile:


Thanks for answering this @imagejan and it’s great to see someone is using it @Claus1. Having to cast script parameters with .asInstanceOf[...] is a annoying stumbling block in the current scala-scripting engine, hopefully this will improve soon.

@ctrueden: no worries. Maybe hold off just a bit longer… Scala 2.12.5 was released a few weeks ago and has a couple of nice enhancements, so I might sneak that in with the same PR.