Is there a way to call ImageJ plugins using the ImageJ.py API, or the ImageJ.py API just for Ops/ImageJ2?
If not, is there a way to call ImageJ plugins using python?
For background: I’m trying to use the grid/collection stitching plugin, but I couldn’t find a way to call it. IJ.find and IJ.run don’t work, and neither does ij.plugin.stitching or ij.plugin.stitching_grid.
I think the problem is that the class of IJ from imagej.init() is net.imagej.imageJ, and those commands are run from just net.imagej.
I can’t answer your specific question about ImageJ.py as I’ve
never used it, but it is possible to run python (jython) scripts
inside of ImageJ. (See below.)
The following is a jython script that you can run from the ImageJ / Fiji
script editor (File > New > Script...):
from ij import IJ
IJ.run ('About ImageJ...')
from ij.plugin import AboutBox
ab = AboutBox()
Running this script will open two copies of ImageJ / Fiji’s About box.
First the script calls IJ.run() with the plugin’s menu entry as a string.
Then it instantiates the plugin directly and calls its run() method.
And here’s a jython script that uses IJ.run() to run the grid/collection
from ij import IJ
IJ.run ('Grid/Collection stitching')
(According to the documentation, jython has one big limitation in that
it can’t use JNI – so numpy, for example, is out – but is otherwise
regular python. Plus jython gives you have access to java classes,
including the classes that make up ImageJ, whether they’re plugins
Thank you for the thorough explanation - I’ll keep this in mind for future ImageJ coding. However, my code is growing into a full python module and would be unwieldy to implement in ImageJ, and it makes heavy use of numpy aside.
I use the grid/stitching algorithm in only one or two places in the pipeline, so it is my hope to be able to call it there. If not, I’ll have to come up with a workflow that involves switching to ImageJ and opening up the script.