2

I am trying to get a home made Fiji script to sun inside Python by calling Fiji, but there's little documentation on how to do it. What I need is something like this:

    def myfijiscript:
        [CODE]

and then in Python:

    fiji(myfijiscript)

is there a way to do this?

Jan Eglinger
  • 3,876
  • 1
  • 22
  • 49
koldrakan
  • 169
  • 1
  • 5
  • I guess you mean ``def myfijiscript():`` with parentheses. What's the problem with simply calling ``myfijiscript()`` (after importing what is needed of course) ? – hivert Jul 18 '13 at 09:30
  • 1
    I assume you checked http://fiji.sc/Scripting_toolbox#Python this link and it's not what you want, right? ;) – Samuele Mattiuzzo Jul 18 '13 at 09:40
  • yeah, I did, and it's great for writing the script I want to use. Calling Fiji to run it from within Python, however, is where the problem is – koldrakan Jul 18 '13 at 10:14

1 Answers1

2

Python (or, to be precise, Jython) scripts within Fiji are executed using the org.python.util.PythonInterpreter class (see source code).

It doesn't make much sense to run a Jython script within a Java instance that is started from with Python, but have a look at those two questions concerning how to run external commands in python. You can save your script in a file myscript.py and then do:

call(["./ImageJ-linux64", "myscript.py"])

using the ImageJ launcher from the command line.

The other way is to use ImageJ as a library and just import the classes you need for your script, as others have suggested:

from ij import IJ
Community
  • 1
  • 1
Jan Eglinger
  • 3,876
  • 1
  • 22
  • 49