This is an archive of the old MediaWiki-based ImageJ wiki. The current website can be found at imagej.net.

Script Templates

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
User input
Basics of script writing
How to use the Javadoc
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

Templates are pre-written scripts in a particular scripting language. They can be distributed as any other plugin, and automatically discovered by the Script Editor. Templates thus present an excellent way to demonstrate a particular operation to a wide audience of users.

Available templates are sorted by language under the Templates menu of the Script Editor. The contents of a template will be loaded into the editor window when selected. The script can then be inspected, executed and modified as normal.

Adding a new template

The Script Editor will automatically search the script_templates directory and register any discovered scripts as templates. For example, a Mavenized project could add a sample script in src/main/resources/script_templates and it would be packaged into the appropriate location of the resultant .jar.

For examples of how the existing templates are structured and distributed, take a look at the imagej-legacy project (which maintains the script templates that were previously shipped with Fiji's script editor) as well as the imagej-scripting project.

Template best practices

Above all else, templates should be well documented. Templates are intended to explain specific functionality in a given language, to users who may have limited experience with the language or programming/scripting in general.

Ideally, a template will be focused on an a single objective (e.g. opening an image, calculating a threshold, operating on a directory, etc...).

It is especially helpful to document how the template can be adapted to meet the user's needs.