Chapter 3. Advanced Image Processing with ImageJ

In the previous chapter, we learned how to read images, the types of images that we can handle, and how to manipulate the intensity levels in order to improve visualization or segment part of the pixels depending on their intensity values. Now we will extend our abilities to measure and manipulate our images. First we will learn what are selections, regions of interest, and overlays, and how to work with them and what can be measured using these tools. After this, we will focus on some classic image processing both in spatial and frequency domains, understanding what that means. Finally, we will see how particle analysis can be done in ImageJ.

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.

Basic selections – lines, length, and profiles

The ImageJ main window with a straight line tool selected (left) and available options for this tools with their corresponding toolbar icons (right).

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:

Basic selections – lines, length, and profiles

The tuberculosis.tif test image with a straight line drawn in order to plot its profile

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).

Change the channel using the slider at the bottom of tuberculosis.tif window, and you will obtain the following profiles:

Basic selections – lines, length, and profiles

Profiles for the three channels in the tuberculosis.tif image, corresponding to Red (top), Green (middle), and Blue (bottom) channels.

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.

Tip

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 [Drawing regions of interest over an area]
  • Oval and elliptical selections, selection brush [Drawing regions of interest over an area]
  • Polygon [Drawing regions of interest over an area]
  • Freehand [Drawing regions of interest over an area]
  • Straight, segmented, and freehand lines [Drawing regions of interest over an area]

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 (Drawing regions of interest over an area). 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 (Drawing regions of interest over an area). 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:

Drawing regions of interest over an area

Four examples of ROIs drawn on the tuberculosis_sample.tif image using rectangular selections (a), circular selections (b), freehand selections (c), and this last example converted to a spline curve (d).

Tip

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 [Drawing regions of interest over an area]. 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:

Drawing regions of interest over an area

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 [Drawing regions of interest over an area].

The ROI manager and the image overlay

In the previous section, you have probably observed that it is very easy to lose your ROI by clicking outside of it. Although we have been working always with a single selection, it does not seem very useful to draw a ROI every time we want to analyze it. ImageJ offers a very powerful tool for this called the ROI manager. It will help you in organizing the ROIs, and also to analyze them.

Open the tuberculosis.tif image. Now navigate to Analyze | Tools | ROI Manager... Display only the Red channel by navigating to Image | Color | Channels Tool... (Ctrl + Shift + Z). Every time you draw a selection you can add it to the ROI manager by clicking on the Add (t) button. This way you can create several independent ROIs that can be updated whenever necessary. After adding the region in the ROI manager you may rename it or modify its properties (for instance, the color). The default name used in the ROI manager is a combination of the ROI coordinates. You can also select a single region to be active by clicking on its name in the ROI list, and even several of them by clicking with the Shift or Ctrl keys pressed. Try to obtain the following result on tuberculosis.tif:

The ROI manager and the image overlay

The tuberculosis.tif image with six oval ROIs and two line selections added to the ROI manager, each with a different color. Note that in order to see all the ROIs in the ROI manager at the same time, the Show all checkbox must be checked.

Drawing ROIs over an image usually has one goal: measuring parameters on those ROIs. ROI Manager also facilitates this step. If we select the first six ROIs in the previous example (by clicking on ROI1 and then on ROI6 while pressing down the Shift key) and then clicking on the Measure button, the following window pops up:

The ROI manager and the image overlay

The Results window after measuring the six ROIs in the previous example. You can easily relate the Mean column with the average ROI intensity in the image.

These results are related to the Red channel that we have selected in this multichannel image (notice the last column in the Results window called Ch). But if we want to measure all channels (or slices in 3D images) and all ROIs at the same time, we can also do it by navigating to More | Multi Measure in the ROI Manager window. The result will have one row per channel, and multiple columns corresponding to different ROIs. Profiles can also be compared by navigating to More | Multi Plot. Use these tools after selecting the two last ROIs called PROFILE1 and PROFILE2 in our example.

Tip

Remember that the Measure results window shown in our examples may be different from the ones that you obtain, because the parameters that will be measured are specified by navigating to Analyze | Set Measurements....

After all that we have learned, you won't assume that you have to lose your work when closing ImageJ. There are two ways to store ROIs: from the ROI Manager or using the Image Overlay. The ROI Manager stores single ROIs by navigating to More | Save... in files with the .roi extension, and multiple ROIs in .zip files. You will need to select the ROIs that you want to save. In a future ImageJ session you can easily recover them from the ROI Manager (More | Open...).

The Image Overlay is like an invisible ROI Manager. It stores the selections or ROIs until you call them back. It is not easy to interact with the ROIs in the Image Overlay, but it has an advantage of being stored with the image when using the TIFF file format. The best way to store your ROIs in the Overlay is to select them and add them to the Overlay by navigating to Image | Overlay | From ROI Manager. After saving your image in the TIFF format, you will be able to recover your ROIs while opening the file by navigating to Image | Overlay | To ROI Manager (the ROI names will probably experience some modifications).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset