ImageJ Example Macros: Automate Image Processing

Charles Jul 17, 2026

ImageJ is a versatile, open-source image processing software widely used in scientific and research communities. While it's feature-rich, many users find it daunting at first. Macros in ImageJ, scripts written in Java, can automate tasks and enhance productivity. Let's explore ImageJ example macros to demystify this powerful tool.

Macro Photography Guide
Macro Photography Guide

ImageJ macros are akin to shortcuts that enable users to perform complex tasks with ease. By recording and editing these actions, users can create custom macros tailored to their needs. Here, we'll delve into creating, running, and customizing ImageJ macros, along with practical examples.

Calorie count
Calorie count

Understanding ImageJ Macros

ImageJ macros are essentially JavaScript code that informs ImageJ how to perform specific tasks. They allow users to automate repetitive tasks, apply complex image processing algorithms, and even create plugins to extend ImageJ's functionality.

the nose of a dog with it's nose close up
the nose of a dog with it's nose close up

To start working with macros, open ImageJ, go to Plugins > Macros > Show Macros. This will open the Macros window, where you can manage your macros.

Recording a Macro

Macro photography
Macro photography

One of the simplest ways to create a macro is by recording your actions in ImageJ. Here's how:

1. Open ImageJ's 'Recorder' by navigating to Plugins > Macros > Record.

2. Perform the actions you want to record, such as opening an image, applying tools, and saving the result.

a kiwi cut in half sitting on top of a reflective surface with its reflection
a kiwi cut in half sitting on top of a reflective surface with its reflection

3. Stop recording once you've completed your sequence. The macro commands will appear in the Results window.

Running and Editing Macros

To run a macro, navigate to the Macros window, select your macro, and click 'Run'.

an apple hanging from a tree with water droplets on it
an apple hanging from a tree with water droplets on it

To edit a macro, click on it, then click 'Edit'. This opens the JavaScript editor, allowing you to modify the macro to your liking.

ImageJ Macro Examples

22 Reliable Macro Photography Examples - DotCave
22 Reliable Macro Photography Examples - DotCave
Macros Cheat Sheet for Easy Calorie Tracking (Beginner's Guide to Hitting Your Goals!)
Macros Cheat Sheet for Easy Calorie Tracking (Beginner's Guide to Hitting Your Goals!)
an orange sliced in half showing the center
an orange sliced in half showing the center
blueberries are piled on top of each other with water droplets all over the surface
blueberries are piled on top of each other with water droplets all over the surface
an assortment of different fruits and vegetables are shown in this collage, including strawberries, raspberries, corn on the cob
an assortment of different fruits and vegetables are shown in this collage, including strawberries, raspberries, corn on the cob
an ant carrying a drop of water on top of a plant
an ant carrying a drop of water on top of a plant
a close up view of a red and white plant's leaf structure with thin lines
a close up view of a red and white plant's leaf structure with thin lines
Лимон
Лимон
the inside of a kiwi fruit slice
the inside of a kiwi fruit slice

Let's dive into some practical ImageJ macro examples to illustrate their power and flexibility.

Batch Processing

Macros can automate batch processing, running the same operations on multiple images at once. Here's a simple example:

`run("otions.Canny Edge Detector");`

`run(" 바뀐named Window", "close");`

`saveAs("jpg", "edgedImage.jpg");`

This macro applies the Canny Edge Detector to an open image, saves it as a new window, then closes the original window and saves the result as a JPG image.

Applying Color Thresholds

Macros can also apply complex image processing algorithms. Here's an example that finds and highlights red cells in an image:

`run("Set Measurements...", "area mean integrated show");`

`run("Analyze Particles...", "show outlines clear");`

`run("Measure");`

`run("Results", " Ier [mean=250:500] add all display");`

This macro measures and displays the area of all particles in the image, then highlights those within a specific size range (250-500 pixels² in this case).

Exploring ImageJ macros can seem daunting at first, but with practice and the right examples, you'll find they're an invaluable tool. So, start recording, editing, and running macros today to revolutionize your image processing workflow.