Advanced Image Processing with ImageJ

Image Processing with ImageJ

September 2013


Get familiar with one of the world’s most highly regarded Digital Image processors, ImageJ. This tutorial takes you through every aspect of viewing, processing, and analysing 2D, 3D, and 4D images, clearly and comprehensively.

(For more resources related to this topic, see here.)

Selecting regions of your image

This section will deal with the process of selecting different regions in your image (lines or whole areas) so that you can perform local measurements using only those selections. Selections, or regions of interest (ROIs), are the basis of region analysis in ImageJ, and open the door to advance measuring of the information in your image, so let's devote some paragraphs to clarify the initial concepts. Let's start by drawing a few lines.

Basic selections – lines, length, and profiles

Open the tuberculosis.tif test image. It is a multichannel image (one 2D image for Red, another for Green, and the last for Blue) and we will use it because working with selections on images of more than two dimensions offers some extra possibilities. The tool to draw a line is the fifth one from the right on the ImageJ toolbar with a line icon. When you move the mouse over it, the status bar will indicate the kind of things you can do. You will probably think that there are too many things in the description for a single tool, but you can actually use four different tools from the same button. This is always true in ImageJ for tools showing a small red arrow at the bottom right of the tool button. Right-clicking on the tool shows a menu with the similar available tools.

Select the straight line tool and draw a line by clicking anywhere on the image and moving the mouse without releasing the mouse button until you want to end your line. While the line is being drawn, the status bar shows relevant information: the current coordinates, the angle of your line with respect to the horizontal and the total length, so you can easily create a line of a specific length. But what if you want to measure your line after you drew it carefully on your image? You only need to navigate to Analyze | Measure ( Ctrl + M). By navigating to Analyze | Set Measurements... You can select which measurements you want to obtain. These are the ones that will be shown on a floating window called Results. Depending on the particular selections done on your ImageJ installation, the parameters shown on your result window will differ from the ones shown here.

A line can also be used to calculate a profile, that is, a plot of the image values along the line. The profile is a simple yet a very useful tool to extract the values along a line that has some meaning in our image. We can use these values to compare the results from different processing algorithms or imaging devices. Draw a straight line on the top-left corner of the tuberculosis.tif image. You should obtain something similar to the following screenshot:

Now plot the profile by navigating to Analyze | Plot Profile (Ctrl + K). The resulting profile corresponds to the red channel, the one that was selected on the image with the channel slider at the bottom. Let's check the profile for the different channels by clicking on the Live button at the bottom right part of the profile window. Now every time you modify something that influences the profile plotting, the plot will be updated in real time; this also applies to modifications of the line itself by clicking and dragging on the points placed along its length (the mouse pointer changes to a hand to indicate that you can click and modify the line).


The line we have drawn crosses two round shapes. The profiles show the intensities along this line in every channel. The big red shape represents values near 100 in the Red channel, below 50 in the Green, and almost zero in the Blue. The small green shape has very high values in the three channels because it is very intense, with a wider coverage for the Green channel.

There is a simple tool that is also available called Angle tool. As you can imagine, by clicking on three independent points it measures the resulting angle. The value is modified if you move any of the vertices.

Results from any measure or profile can be saved in a text file extensions, allowing you to analyze these data with other software such as Microsoft Excel.

Drawing regions of interest over an area

In the previous section we presented the straight line tool and also indicated that the corresponding button in the toolbar allows selecting another three tools: Segmented Line, Freehand Line, and Arrow Tool. These are a part of a group of tools that ImageJ facilitates in order to draw selections, that are areas of the image that can be used to measure all kinds of parameters (area, length, maximum, perimeter, and so on) or to specify which pixels of the image will be taken into account in further processing steps.

We can draw ROIs by combining several tools. The simplest one is the straight line. All these tools are together in the ImageJ toolbar, and are as follows:

  • Rectangle and rounded rectangle tools
  • Oval and elliptical selections, selection brush
  • Polygon
  • Freehand
  • Straight, segmented, and freehand lines

Instead of giving a full description of what every tool is and how it is used, we will give you some general guidelines that apply to all of them. After reading them, we will propose you play with them for a while so that you can practice.

All tools (except the selection brush) create a shape by clicking with the mouse and moving it without releasing the button until you want to finish. If the tool has options, they can be accessed by double-clicking on the tool icon. The polygon tool creates a side of your polygon every time you click, and closes the shape by double-clicking.

When you have created your selection, it can be translated by clicking on it and moving the mouse before releasing the button, provided that the mouse cursor is showing an arrow icon The ROI can be modified by clicking and moving any of the control points, and in that case the mouse icon will change to a small hand When this resizing is done, while holding down a modifier key some restrictions are applied: Shift forces a 1:1 aspect ratio of the selection, Ctrl forces resizing from the center of the selection, and Alt keeps the original aspect ratio. These keys have different effects depending on the kind of selection, and in some cases they won't have any effect. Arrow keys also move the selection, and when combined with Alt, they resize the selection pixel by pixel. Draw different ROIs on any sample image and try all this with different selection tools to understand the possibilities better.

When creating selections to be combined with existing ones, use the Shift and Alt keys as modifiers to add and delete newly created selections to existing ones. If you have a selection in your image and want to combine it with the one you are going to create, press Shift while creating it. On the other side, press Alt while creating a selection and it will be removed from the existing one. The result is called a composite selection.

Finally, the polygon selection has control points that can be moved independently. If after drawing your polygon you would like to have more control points than the ones you have created, you can click on one control point and press Shift at the same time. The existing control point splits into two, allowing a more detailed modification of the selection. If you prefer to remove some control point just click on it and press the Alt key. An ROI created with the freehand tool won't have control points, but ImageJ offers a way to convert it into a smooth curve with control points by navigating to Edit | Selection | Fit Spline.

As a final exercise, try to obtain the following ROIs on the tuberculosis_sample.tif image as follows:

Now that you have full control of how to draw different kinds of selections, check how a profile plot can be drawn also from a polyline or a freehand line.

The remaining type of tool is the wand tool . This tool is a bit different from the previous ones, as it does not require you to draw the desired contour, but instead generates one based on the pixel values of the region surrounding the initial click. This is called region growing segmentation. When you double-click on the tool icon, a dialog will be shown asking for Mode and the Tolerance. The tolerance is the amount of change that will be permitted in the pixels included in the region, compared to the value of the pixel used as a seed (the one that is being clicked on). The mode selection can be used to impose additional restrictions, such as the need for the pixels to be connected with other pixels already in the region.

The following example shows the application of this tool on the tuberculosis_sample.tif image using the Legacy mode and a tolerance of 20.0. You can see that it automatically draws your contour around pixels with values within the range defined by the tolerance:

If you want to remove any selections in the image, the easiest way is to select the rectangular region tool and click (but not drag) on any point outside the current selection. When you click on an image with an area selection tool, existing ROIs are deleted. It may sometimes happen that you have accidentally created a very small region and your analysis results are not the ones you are expecting, so this is a very fast way of removing this possible source of errors.

Finally, you can also set regions consisting of an individual pixel using a single point (or multipoint) tool .


In this article, you have learned how to draw regions of interest over your image, save them for later use, and perform local analysis. Also, the filtering concept has been introduced along with several useful applications. Finally, we have shown how to combine several tools in order to clean an image and perform a particle analysis over it.

Resources for Article :

Further resources on this subject:

Books to Consider

comments powered by Disqus

An Introduction to 3D Printing

Explore the future of manufacturing and design  - read our guide to 3d printing for free