Scripting Headless

Learn
Topics
Introduction
Getting Started
User Guides
Tutorials
Tips and Tricks
Presentations
Plugins
Techniques
All Techniques
Colocalization
Deconvolution
Registration
Segmentation
Stitching
Tracking
Visualization
Scripting
Overview
Parameters
Basics of script writing
Batch processing
Script Editor
Auto Imports
Templates
Running headlessly
Comparisons
Toolbox
Multithreading in Clojure
Multithreading in JavaScript
Chess in Jython
Languages
BeanShell
Groovy
ImageJ Macro
JavaScript
Lisp (Clojure)
MATLAB
Python (Jython)
R (Renjin)
Ruby (JRuby)
Scala

ImageJ scripts are designed to operate independently of user interface—including headless, with no user interface. This is made easy with the use of script parameters.

To start ImageJ in the ImageJ2 headless mode, run (with the launcher appropriate for your system substituted):

./ImageJ-linux64 --ij2 --headless

By default, when ImageJ runs headlessly it acts like a one-off program: it will only perform the requested operations, then quit. To run a script headlessly, use:

./ImageJ-linux64 --ij2 --headless --run path/to/script [key1=value1,key2=value2,...]



Basic run

Let's say we have the following Python script saved in a file, hello.py:

# @String name

print('Hello ' + name)

we could run this script with the command:

./ImageJ-linux64 --ij2 --headless --run hello.py 'name="Mr Kraken"'

Note that the name parameter must be enclosed in double quotes, since it is a string literal.

Multiple parameters

If your script has more than one parameter:

# @String name1
# @String name2

print('Hello ' + name1 + " and " + name2)

then these are filled by using a comma-separated list of parameter pairs—e.g.:

./ImageJ-linux64 --ij2 --headless --run hello.py 'name1="Mr",name2="Mrs Kraken"'