Skip main navigation

Batch processing in Fiji

How to perform batch processing using Fiji.

Often when performing imaging analysis tasks, it’s not just one image that needs some post-processing but a whole series of images in a data set (e.g. a set of replicates from an experiment). Though you could go through each image one-by-one in Fiji performing the same set of steps each time, it’s much better to use batch-processing.


In batch processing you supply Fiji a set of files and a set of instructions, and it performs the same instructions on each file in the set and saves the results in a location of your choice. The reasons for doing this are two-fold. The first, and most obvious reason is speed. The second reason is accuracy. The more complex your analysis, the more likely you are to make errors in performing it (e.g. setting a threshold or other parameter in a plug-in). Provided you get the analysis right the first time, using batch processing ensures an identical analysis is done on every file in your data set.

The simplest way to run a batch process menu is through the batch process GUI window that you can open from the Process -> Batch -> Macro menu.

A screenshot of the process of accessing the Macros menu in Fiji, via the Process, then Batch menus.

This brings up the following window:

A screenshot of the batch process menu in Fiji. There are fields for Input and Output directories, and output file format, as well as a large text box for entering macro code.

First you need to select an Input directory and Output directory at the top of the window, making sure that the input directory has the correct data, and that the output directory does not have any data you don’t want to write over. You can also select an output format for your images. For more on image formats see the article from week 1.

The same batch process menu in Fiji as above, with the fields for Input and Output directories, and output file format highlighted.

Standard Macros

If your task is simple, you can use the drop-down menu labelled “Add macro code” and pick from a set of common functions. This will automatically add snippets of code in the text box below. The code is written in a Fiji specific language known as ImageJ Macro language. For example if you select “Scale” from the list it will add code as follows:

The same batch process menu in Fiji with the 'add menu code' dropdown box and automatically generated code shown in the macro code text box.

Here the scale used has defaulted to 1.5 times the original value, but it’s easy to change this by just changing the value to whatever you want. For example, typing 0.5 in the box means that every image will be scaled to half its original size. To run the batch process, just click “Process” in the bottom left of the window. Whilst not identical to any full programming language, it is fairly intuitive, and if you learn Python (for example through some of the units on this course) you will see some similarities.

Recording Macros

In many cases the analysis or processing you want to do with your images is not going to be contained in the standard set in the ‘Add macro code’ menu. If this is the case, unless you want to learn the ImageJ macro language and type code directly into the text box, the best way to set up your batch process is to record a new macro. To record a macro you first need to open up an example image to work on, then select Plugins -> Macros -> Record to bring up the macro recording window.

A screenshot of the Macro recorder window in Fiji, without anything recorded in the text box.

After this every action you take in Fiji will be recorded by the macro (so it’s important to plan your analysis carefully beforehand!). For example, if you wanted to perform an Otsu segmentation on your images, you would first convert to grayscale:

  • Image -> Type -> 8-bit

Then to do the segmentation:

  • Image -> Adjust -> Threshold
  • Select ‘Otsu’ from the dropdown menu
  • Tick the ‘Dark background’ box
  • Click ‘Apply’

As you progress, the macro window will automatically fill with code. With the steps above the window should look something like this.

A screenshot of the Macro recorder window in Fiji, with the code to execute an Otsu thresholding step recorded in the text box.

When you’re happy with the results in your example image, you can save your macro. After adding a suitable name in the box at the top, click the ‘Create’ button. This will bring up another window, and the option to save the macro from the File menu.

Then, to add the new macro code to the batch process window you can just click ‘Open’ toward the bottom left of the batch process window, select the newly saved macro and the code should appear. Alternatively you can just copy and paste the code from the macro recorder to the batch process window.

As before, to run the batch process, just click “Process” in the bottom left of the window.

To note, some processes in Fiji won’t record very accurately or even at all for technical reasons, so as with all programming it is important to check the macro you have recorded does in fact function as intended! Testing code is as important, if not more important and challenging, than the initial code writing.

This article is from the free online

Introduction to Image Analysis for Plant Phenotyping

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education