ImageJ is a Java image processing and analysis application developed at the US National Institute of Mental Health (NIMH). Although it's intended to be used interactively via a GUI interface, its functionality is also available through an extensive API, which is the focus of the examples on this page.
This dual approach is actually quite helpful since it's possible to turn on the Plugins >> Macro >> Recorder feature which converts menu selections into API statements that can be pasted into your code. Another useful menu item is Plugin >> Utilities >> Find Commands which lets a user discover which Java class is used to implement a particular menu feature.
There's extensive documentation, including a PDF version of the user guide, but most of the material focuses on the GUI. That's one reason for my creation of these examples.
ImageJ's core functionality is located in ij.jar, and its source can be browsed online, although I prefer to decompile the JAR's code using JD-GUI. The three most important classes are probably IJ, ImagePlus, and ImageProcessor.
Two rather brief sources on how to program with the API are Albert Cardona's ImageJ Programming Tutorial, and an ImageJ/Java Cheat Sheet prepared by Wilhelm Burger and Mark J. Burge as part of their excellent text, Digital Image Processing - An Algorithmic Introduction. The Burger and Burge text utilizes ImageJ plugins, small Java programs that add functionality to the basic ImageJ GUI. The ImageJ plugin page hosts several hundred ready-to-use add-ons, including the 50 or so developed for the book. In addition, ImageJ also supports a macro language, and its website hosts over 300 macro examples.
My examples are NOT plugins or macros, but standalone programs using ImageJ's API. In particular, there's no need to start the GUI interface shown above.
One possible source of confusion, especially when searching for ImageJ resources on the Web, are the related ImageJ2 and Fiji projects. ImageJ2 is a rewrite of ImageJ for multidimensional image data, with a focus on scientific imaging, while Fiji describes itself as a "batteries-included" distribution of ImageJ2, bundling a lot of plugins for image analysis. However, ImageJ is still in active development, with the current version released in March 2023.
> compile.bat ShowPic.java > run.bat ShowPic frankenburg-1918.pngThe picture passed to ShowPic can be obtained from here.
Some of the examples use add-ons which aren't included with the basic ImageJ download. They are:
Plugins should be placed in ImageJ/plugins/, and macros in ImageJ/macros/.
The examples are divided into four rather arbitrary categories, and a few of them are listed more than once because of the range of features they use.
You may found it convenient to download all the code (including test images) as one zipped file (4.6 MB). Unzip the folder, and add the ImageJ/ directory to it so that the compile.bat and run.bat scripts can find the API, plugins, and macros.
Most of the examples in this section use third-party plugins and macros that aren't included in the ImageJ download.
The following are used by several examples: