Image Processing With ImageJ - Second Edition - Sample Chapter
Image Processing With ImageJ - Second Edition - Sample Chapter
ee
Second Edition
Advances in image processing have been vital for the
scientific and technological communities, making it possible
to analyze images in greater detail than ever before. But
as images become larger and more complex, advanced
processing techniques are required. ImageJ is built for the
modern challenges of image processing it's one of the key
tools in its development, letting you automate basic tasks so
you can focus on sophisticated, in depth analysis.
This book demonstrates how to put ImageJ into practice.
It outlines its key features and demonstrates how to create
your own image processing applications using macros and
ImageJ plugins. Once you've got to grips with the basics
of ImageJ, you'll then discover how to build a number of
different image processing solutions. From simple tasks
to advanced and automated image processing, you'll gain
confidence with this innovative and powerful tool however
and whatever you are using it for.
Jurjen Broeke
Jos Mara Mateos Prez
Javier Pascau
P U B L I S H I N G
Sa
m
pl
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
$ 39.99 US
25.99 UK
Second Edition
Extract and analyze data from complex images with ImageJ,
the world's leading image processing tool
Jurjen Broeke
Jos Mara Mateos Prez
Javier Pascau
Javier Pascau received his PhD from Polytechnic University in Madrid in 2006
and is currently a visiting professor at Carlos III University, Madrid. He has been a
part of Biomedical Imaging and Instrumentation Group, a research laboratory with
a multidisciplinary team of engineers, physicists, biologists, and physicians located
both in the university as well as Hospital General Universitario Gregorio Maran
(biig.uc3m.es). Javier's research and teaching cover areas such as medical image
processing, analysis, quantification, and multimodal registration, both in preclinical
and clinical environments. He has been involved in the development of small
animal PET and CT devices. In the last few years, Javier has led several projects on
intraoperative radiation therapy and image-guided surgery. He has authored more
than 40 papers published in peer-reviewed journals over the last 15 years.
Preface
Advances in image processing are vital for the science and technology communities.
However, as images become larger and more complex, even more advanced
processing techniques are required. Automation becomes necessary too so that you
can perform simple tasks easily and focus on more sophisticated issues. ImageJ
is here to helpas one of the key powerful tools in the development of image
processing, it lets you extract even more useful data from your images.
Preface
Chapter 5, Basic Measurements with ImageJ, considers some methods to measure the
parameters within images and time series. We will apply some of the techniques
discussed in previous chapters to extract data from our images. You will also learn
how to visualize dynamic data in a single image (kymographs).
Chapter 6, Developing Macros in ImageJ, discusses how to create a macro using a
recorder to discover the commands and functions that we can apply. Next, we will
take a look at processing a folder full of images and saving the resulting images to
the hard disk. Finally, we will look at the Batch Process mode, which allows ImageJ
to process a folder in a similar way.
Chapter 7, Explanation of ImageJ Constructs, looks at the framework of macros and
plugins that are available in ImageJ. We will discuss some of the constructs that
the ImageJ API exposes for use in scripting and plugins. Finally, we will describe
how to set up an IDE to develop ImageJ and plugins using it as a standalone or
Maven-based project.
Chapter 8, Anatomy of ImageJ Plugins, takes a look at the anatomy of plugins for
ImageJ1.x and ImageJ2. We will also take a look at some of the specific constructs
that are used in plugins for both frameworks. This chapter examines how to compile,
run, and debug plugins using the IDE or tools provided by ImageJ.
Chapter 9, Creating ImageJ Plugins for Analysis, develops a plugin from scratch using
the Maven system and NetBeans IDE. We will discuss how to add a basic user
interface to our plugin, allowing the user to change some of the parameters that
influence the way the plugin functions. We will also add an external library to
provide additional functionality that was not present in ImageJ.
Chapter 10, Where to Go from Here, sums up the topics that are discussed in previous
chapters and provides further resources that are available for you to continue
developing your own plugins. The chapter also looks at some of the more advanced
techniques that are available for developers.
ImageJ distributions
Currently, there are different distributions that are based on or are extensions of the
original ImageJ. The basic ImageJ package is available on the ImageJ website at the
National Institute of Health (http://imagej.nih.gov/ij/download.html). The
current version of the package is version 1.50b, and the website is updated monthly.
This is the core distribution of ImageJ, which contains the main interface and all the
basic tools to load, view, process, and export images and data. Other distributions
contain this core package and most of its features, but you need to add additional
features and plugins to create an optimized interface for specific fields. Some of
these other distributions are still easily recognizable as ImageJ, while others offer a
completely different interface.
[1]
For different scientific fields, different distributions were developed based on the
core of ImageJ. One of the major distributions for the life sciences is called Fiji (Fiji
Is Just ImageJ), which can be found on the Fiji website (http://fiji.sc/Fiji).
The basis of Fiji is ImageJ, but it comes with a large complement of preinstalled
features (macros and plugins) that are commonly used for image processing in
the life sciences. It is focused on fluorescence microscopy, with built-in tools for
segmentation, visualization, and co-localization. It also contains plugins for image
registration, particle tracking, and super-resolution processing and reconstruction.
It also has an extensive library of image formats that can be opened. This library
includes proprietary image formats from all the major acquisition software packages
via the Bio-Formats plugin, as described in the upcoming section. The advantages of
this distribution are the large number of supplied plugins that come with it as well as
a very user-friendly script editor. It also has an extensive update mechanism for both
ImageJ as well as some plugins.
For the field of astronomy, a different distribution of ImageJ was developed, named
AstroImageJ (http://www.astro.louisville.edu/software/astroimagej/).
This distribution takes the core implementation of ImageJ and supplements it with
specific plugins and macros developed for analysis in the field of astronomy. It is not
directly compatible with ImageJ. The core of ImageJ was slightly modified for this
distribution.
An example of a distribution derived from ImageJ but with a different user interface
is Icy (http://icy.bioimageanalysis.org/). The Icy distribution has integrated
ImageJ, and many plugins are compatible. However, not every plugin developed for
ImageJ will work within Icy and vice versa. In the Icy distribution, there is a strong
emphasis on cellular and spot detection and tracking. There is also a strong emphasis
on plugin development. Plugins that are developed for the Icy platform will have
documentation and automated updating implemented by design. There are also
possibilities for users to directly provide feedback to the developers from within the
interface, which is a feature not present within other distributions based on ImageJ.
A disadvantage may be that it requires several external libraries to be installed, most
importantly VTK, which can cause issues on Linux systems.
Another distribution that uses ImageJ not only for the processing of data but also
aids in the acquisition of data is called Manager, which can be found at https://
www.micro-manager.org/. It is loaded from within ImageJ as a plugin, but provides
a unique interface geared towards image acquisition and hardware control. Camera
and microscope drivers allow the control of supported hardware used in image
acquisition, which can then be fed directly to ImageJ for processing and analysis.
An example of the use of Manager is in the Open SPIM project, where it is used to
control a DIY light sheet microscope, acquire images, and process them.
[2]
Chapter 1
[3]
It can also be used as an image-conversion tool. Many image formats can be read
natively by ImageJ, and with the help of a plugin, many proprietary formats can be
opened. Once the image is opened, it can be saved to any of the supported export
formats supported by ImageJ, including, but not limited to TIF, JPG, and PNG for
images and AVI and MOV for time series and Z-stacks. It can also be used to change
the order and/or color of images exported by other software. It is, however, not
meant as a general photo editor or nonlinear video editor, as it lacks some of the
specialized tools required for these workflows.
ImageJ2
ImageJ is still under active development, and new features and bug fixes are added
to the core distribution on a regular basis. Currently, the development of a revised
system for ImageJ is being developed. It is called ImageJ2. The goals of ImageJ2 are
to better support multidimensional data as well as create a more extensible platform
that can be used as a library instead of a standalone application. It will also create
a more consistent environment for development and extension. One of the features
being developed is the updating mechanism for ImageJ. Currently, it is possible
to update ImageJ automatically using a central repository, and one of the goals of
ImageJ2 is to expand this option to plugins and other features and allow tracking of
bugs and features. However, one of the core requirements in the new ImageJ2 system
is backward compatibility. This goal means that plugins developed now will stay
functional in future releases of ImageJ. The current status is indicated as beta, which
means the plugin is functional but may still contain bugs and is not optimized for
performance yet.
[4]
Chapter 1
Bio-formats
Besides the OME-XML format, which is focused on integrating acquisition and
processing across multiple acquisition platforms, there is also active development of
the plugin used to import many image formats currently in existence. This plugin,
called Bio-Formats, is mostly focused on image formats from the life sciences.
However, it also supports FITS data, which is used in the field of astronomy and
space exploration. It currently supports (to different degrees) 140 different image
formats and converts them to the OME-XML format for use in ImageJ.
[5]
Installation of ImageJ
When you download a copy of ImageJ, the JRE can be provided along with it. If you
already have a copy of the JRE installed, you could download ImageJ without the
JRE for a faster download. The minimal requirements to run ImageJ are JRE Version
1.6 or higher. For some distributions, most notably Fiji, the JRE has to be version 1.6.
This limitation is due to the current implementation of the updater included with
Fiji, which is not capable of updating the JRE. This problem may be resolved in
the future.
As ImageJ comes with its own JRE, it can be extracted on a USB drive and run from
there without installation. The only limitations on the system are dependent on
the size of the images. ImageJ loads images directly into memory, so the available
system memory needs to be large enough to hold the images you wish to process.
When memory requirements exceed 3 GB, a 64-bit operating system with a 64-bit
JRE is required.
Since ImageJ is platform independent, you could use the same version on all three
platforms: Windows, OS X, and Linux. The only platform-dependent part is the JRE;
for each platform, there is a specific JRE installation. The following sections will
explain how to install ImageJ on each of the operating systems.
Installing on Windows
In order to install ImageJ on Windows, you can download the latest version from the
ImageJ website at the NIH (http://imagej.nih.gov/ij/download.html) or for Fiji
from the Fiji website (http://Fiji.sc/Downloads). When downloading from the
NIH website, there are two choices: an installer for 32-bit or 64-bit systems and a ZIP
archive when you wish to run ImageJ on a platform without installer privileges.
[6]
Chapter 1
When using the installer version, it is generally not recommended that you install
ImageJ in the Program Files folder. Certain files within the ImageJ folder need to
be modified when using the program, so when running it as a regular user, access
problems may occur. Also, when installing or creating plugins, the compiled files
need to be placed in the plugins folder within ImageJ. This folder may not have
write permission when it is located in the Program Files folder for regular (nonadministrator) users. Alternatively, you could change the access permissions for the
ImageJ folder specifically. However, this is not recommended from a security point
of view.
Double-clicking on the ImageJ.exe file within the extracted folder will start ImageJ.
This file is a wrapper executable that calls the ij.jar file and uses the supplied JRE
to run it. The Fiji distribution comes as a ZIP archive that can be extracted on a disk
and run immediately:
Installing on Mac OS X
ImageJ is available for Mac OS X as a ZIP archive that can be extracted to a folder
within the Applications folder. The Fiji distribution can be downloaded as a DMG
file that can be dropped in the Applications folder. This will install the ImageJ folder
and make it accessible for all registered users. It will also create a Fiji icon in the
app drawer. If you wish to import or export QuickTime movies under OS X 10.10
(Yosemite), you need to download the QTJava.zip and libQTJNative.jnilib files
from http://imagej.nih.gov/ij/download/qt/ into your home directory within
the Library/Java/Extensions folder.
Note that in OS X 10.7 and later, you may receive a warning the first time you try
to run ImageJ. This warning will say ImageJ can't be opened because it is from an
unidentified developer. This can be resolved by going to the system settings and
pushing the allow button in the security and privacy panel. This should prevent
this warning from showing up in the future. Alternatively, you can select the
Anywhere option from the Allow apps downloaded from section. The latter option
is not recommended from a security point of view, as it might also allow malicious
software to be executed.
[7]
Note that when ImageJ (or Fiji) is run on OS X, the menu bar is not part of the main
window as in Windows:
Installing on Linux
ImageJ can be installed on Linux platforms by unpacking the distribution from the
NIH website. The distribution from the NIH website is available as a ZIP file, while
the Fiji distribution is available as a tar.gz file. For most Linux distributions, it is
recommended that you extract the archive to a location within your home folder.
This prevents problems with write permissions on the ImageJ folders. The folder
contains a shell script to run ImageJ. This shell script is named ImageJ. For different
desktop environments, methods exist to create a shell shortcut to this script to allow
it to run from a shortcut.
[8]
Chapter 1
Plugins folder
The two most important folders are the macros and plugins folders. These folders
will be searched for available macros and plugins when ImageJ loads. When you
download a plugin and place it in the plugins folder, the plugin will be found
the next time ImageJ starts. When downloading plugins, there are three different
options of files that can be downloaded: a Java source file (.java), a compiled file
(.class), or a Java archive (.jar). In order for plugins to be displayed in the plugins
menu, the .java and .class files need to contain at least one underscore character
in the filename. For .jar files, the archive needs to contain a plugins.config file
that defines the location within the menu system. This has an additional advantage
that plugins within a .jar archive can also be installed outside the plugins menu.
Underscores are replaced by spaces in the plugins menu or removed completely if
the last character is an underscore. If you place your plugins in a folder within the
plugins folder, this folder name will also show up in the Plugins menu, but only if
it contains at least one valid plugin. If you download the source file of a plugin, you
can create an executable plugin by choosing Compile and Run from the Plugins
menu and selecting the Java file. The next time ImageJ is run, the new plugin will be
automatically detected.
JAR files are slightly special. They can be placed within the plugins folder, but
they do not have to show up in the Plugins menu. The JAR file contains a manifest
that specifies the location where the plugins within it are placed. This specification
allows the developer to place the plugin in a specific submenu of the Plugins menu,
regardless of the folder where the JAR file is placed. This would be especially handy
if you create a group of linked or associated plugins that you wish to group within
the Plugins menu.
Macros folder
The macros folder contains a collection of macros that come with ImageJ and is
also the default location to store user-defined macros. ImageJ macros are flat text
files with the .ijm extension, although this extension is not essential. Any flat text
file with valid macro code can be run in ImageJ. Macros in ImageJ have their own
language, which is similar to Java, but with a few minor differences. Chapter 5, Basic
Measurements with ImageJ will investigate how to create macros and will explain the
language constructs in ImageJ macros.
[9]
This tells the computer to run ImageJ with 1024 MB (1024m) of memory. If you
need more, then you can change the value of 1024m to whatever value is suitable.
However, make sure that you do not use more memory than is available on your
system.
Another setting that is important to verify is in the Appearance dialog. The
Interpolate zoomed images option should be unchecked for image processing. This
option can interfere or give misleading results when processing:
[ 10 ]
Chapter 1
If you plan to work with images containing a lot of white pixels, it is also advisable
that you change the selection color to a different value than the default Yellow. This
can be done via the Colors setting in preferences. A good default value in many
cases is Orange or Green.
Summary
In this chapter, we looked at the origin and use of ImageJ, and discussed how
to download and install it on different platforms. We looked at the basic folder
structure of the ImageJ installation and configured it for use. Everything should
now be set up to start with the first steps in image processing.
[ 11 ]
www.PacktPub.com
Stay Connected: