The Script Editor of Fiji

My Favorite Bioimage Analysis Tools, by NEUBIAS members

  • Fig. 1: Script Editor and its components.Fig. 1: Script Editor and its components.
  • Fig. 1: Script Editor and its components.
  • Fig. 2: Command auto-completion for build-in macro functions (A) and custom variables and functions (B).
  • Fig 3: Command-Line Interface for Fiji.
  • Fig. 4: An example ImageJ macro for processing with Batch button.
  • Fig. 5: An example Jython script for processing with Batch button.
  • Kota Miura: International Christian University (Tokyo, BLA), Osaka University (Master of Physiology), LMU (Zoological Institute, Munich, Ph.D.), EMBL (Heidelberg, Postdoc & Staff scientist), National Institutes of Natural Sciences (Tokyo, Associate Professor). He now works as a freelance analyst, associated with Heidelberg University as a visiting bioimage analyst and the vice-chair of the Network of European Bioimage Analysts (Neubias).
Many people reading this arti­cle probably have already used ImageJ [1], or it’s powered-up distribution Fiji (ImageJ2) [2, 3]. ImageJ is generally used as a tool to easily work on image data interactively. But ImageJ can do more than that; it can be used to write scripts, and easily reuse or customize them. Scripts are important not only for automating one’s own analysis, but also as the way to document analysis workflow as reproducible scientific method.
Fiji comes bundled with a simple script editor. This script editor has been extended by more features recently, and as there has been no concise overview of these new functionalities yet as long as I know, this article aims to first briefly describe its classic features and then focus on these new features. With these new features, the script editor is becoming the IDE (Integrated Development Environment) for bioimage analysis in Fiji. The script editor is indeed my favorite tool for bioimage analysis over the last 10 years, and I am impressed that it is evolving even further.
Classic Features
To start up the script editor, select File > New > Script ... in Fiji. The editor appears in a new window (fig. 1). The menu tree of the script editor is different from that of ImageJ menu bar and has its own menu items focused on the assistance for scripting. Using the menu under Language >, we can choose a programming language from ten different ones that are supported: Beanshell, Clojure, Groovy, ImageJ (IJ1) macro, Java, Javascript, Python (Jython), R (Renjin), Ruby (JRuby) and Scala.
Figure 1A is the text field where we edit a script. That script can be quickly executed by clicking the “Run” button (fig. 1-1). This execution (“Run”) can be done even before saving the script as a file, allowing us to rapidly cycle through code writing, testing and updating. The code becomes automatically highlighted to visually assist the writing and the debugging of the code (syntax highlighting): comments are in green, commands are in bronze, strings are in magenta and statements are in blue.

At the moment, we cannot change the color scheme of syntax highlighting. Maybe we will see such options in the future. One hidden shortcut for editing that is not accessible from the menu but that is quite useful is command-/ (or control-/). It toggles the comment/uncomment of a single line.
The console at the bottom is for displaying the output of execution (fig. 1B). Note that with ImageJ macro, text output coming from print command appears in a separate Log window unlike other languages. The “Show Errors” button (fig. 1-5) allows us to toggle between standard and error outputs, and these outputs can be refreshed by the “Clear” button (fig. 1-6). A running script can be force-terminated by the “Kill” button (fig.1-3). When this button is not effective enough to stop the script, we can use the more powerful Plugins > Utilities > Thread Killer to terminate the running script.

Recent Features
The initial release of the script editor was ten years ago authored by Johannes Schindelin (@JSchindelin) and now maintained by Curtis Ruden (@ctrueden). During last two years several excellent features have been newly added by other contributors. With these updates, the script editor is becoming more like an IDE for bioimage analysis.
Code Auto-Completion for ImageJ Macro
Code auto-completion is a functionality that assists the programmer by showing a list of candidate commands and variables as you type. This is just like the autocompletion function you know when you type texts in smart phones. Instead of general words, code auto-completion focuses on available commands e.g. ImageJ macro build-in functions (fig. 2A) and variables that are already defined in the script (fig. 2B). It also provides help texts for each candidate terms to assist the coding (fig. 2, yellow panel). This excellent new feature was contributed by Robert Haase (@haesleinhuepf) and is being further developed.
Read-Eval-Print Loop
In addition to the traditional menu tree accessed using mouse, Fiji now has an interactive command-line interface for image processing and analysis, integrated as a part of the script editor. This functionality is called Read-Eval-Print Loop (REPL) in the computer world and you might know such an interface in R, Python or Matlab. It was newly built into the script editor in May 2019 contributed by Albert Cardona (@albertcardona). To launch REPL in the script editor, tick “persistence” check box (fig.1-4). Then the console (fig.1-B) splits horizontally into two panels, and the lower one is the input field where you type your codes (fig. 3), and by hitting return key, the command is executed. Outputs is then printed in the upper panel. Up/down arrow keys allow you to go back through the history of commands, and this is quite useful if you want to repeat recent commands. One missing feature is the autocompletion in this REPL, which needs a merging with the project by Robert Haase already described above.
The arrowhead button (fig. 1-7) is another new feature that came along with the addition of this REPL interface. Clicking this button toggles the arrangement of panels between horizontal and vertical split. Smaller arrowhead icons (fig. 1 circles) are also new feature for arrang­ing panels. By clicking these arrowheads, we can hide or expand editing panel (fig. 1-A) and file system tree panel (fig. 1C, more details below).
File System Tree
The latest version of the script editor has a side bar with file system tree in the left side of the script editor (fig. 1C), an­other new feature contributed by Albert Cardona. The default folder is the user root folder that is there from the start, and other folders in the file system can be added or removed by + and - button at the top of this panel. Folders can be expanded or collapsed by double clicking. By drag & dropping a file from the tree into the editing panel (fig. 1A), the absolute path to that file is inserted as text. This saves the extra step we often take to find out the file path for loading the file in the script. Drag & dropping an image file to the Fiji menu bar opens that image, and this is like having a pinned folder where we can easily access and manually open images and view them in Fiji quickly.
Batch Button
There are several ways to batch-process multiple image files in Fiji. The first way is the batch processors under Process > batch >. The second way is Process > Multiple Image Processor. The third way is to write a full script that loops through the list of files generated by accessing file system in the code (e.g. In script editor, Templates > ImageJ 1.x > Batch > Process Folder (IJ1 Macro)). The Batch button (fig.1-2) is the fourth way (a new functionality under development but already usable) contributed by Jan Eglinger (@jan_eglinger). Following is an example usage of the Batch button. Let us say that we have multiple image files in a folder and we want to measure the mean intensity of each. We then write a ImageJ macro for a single file such as the one shown in figure 4.
Then click the Batch button. In a new window, the file system tree is shown and we select all TIFF files that we want to measure by shift-clicking, and clicking Open. The batch processing starts and when it finishes, there will be a list of mean intensity in the Log window. The code becomes more simple and straight forward with Jython (fig. 5).
It might look overly redundant to have the fourth way to do batch-processing in Fiji, but from the developer’s point of view, it utilizes the power of “script parameters”, one of the features newly introduced in ImageJ2 [4] and the mechanism in behind is different from the previous ones. Within codes shown in figure 4 and 5, lines starting with “#@” are the script parameters. For more details about script parameters, please refer to its web page [5].
The script editor is a simple programming tool integrated with Fiji, but it has essential features for efficient coding. Many new useful features have been added recently. The editor became even more attractive to use for composing bioimage analysis workflows.
I thank Sébastien Tosi for checking the text. Neubias is a Cost Action supported by EU (CA 15124).


Kota Miura


Dr. Kota Miura (@cmci_)

Freelance Bioimage Analyst
Nikon Imaging Center
Heidelberg University
Heidelberg, Germany


[1] Schneider, Caroline A et al. “NIH Image to ImageJ: 25 Years of Image Analysis.” Nature Methods 9, no. 7 (July 28, 2012): 671–75.
[2] Schindelin, Johannes et al. “Fiji: An Open-Source Platform for Biological-Image Analysis.” Nature Methods 9, no. 7 (July 2012): 676–82.
[3] Pietzsch, Tobias et al. “ImgLib2--Generic Image Processing in Java.” Bioinformatics (Oxford, England) 28, no. 22 (2012): 3009–11.
[4] [last visited: 18.11.19]
[5] Rueden, Curtis T., Johannes Schindelin, Mark C. Hiner, Barry E. DeZonia, Alison E. Walter, Ellen T. Arena, and Kevin W. Eliceiri. “ImageJ2: ImageJ for the next Generation of Scientific Image Data.” BMC Bioinformatics 18, no. 1 (November 29, 2017): 529.


Freelance Bioimage Analyst Nikon Imaging Center Heidelberg University

Register now!

The latest information directly via newsletter.

To prevent automated spam submissions leave this field empty.