Image adjust tools

In this section, we will explore different tools that can be used for basic image processing.

Image histogram and window/level parameters

In this section, we will first understand one basic descriptor of the image intensity content, the image histogram. It will allow us to better understand what the intensity processing tools are doing. The image histogram is a graphical representation of the intensity values present in the image that plots the number of pixels for each intensity value. It shows intensity distribution over the image at a glance, and will help a lot when adjusting the way these intensities are displayed or modified.

Histograms, like most of the concepts in this book, are better understood with examples. Open two test images: happy_face.jpg and tuberculosis_sample.tif. If you look at these images side-by-side, you will notice that the intensity distributions are quite different, that is, happy_face presents a similar intermediate intensity along the image (gray pixels), with almost no dark or bright areas, while tuberculosis_sample has large areas with low intensity (dark pixels), and some high intensity spots (bright pixels). Now we will take a look at the histograms of every image. Select each image window and run Analyze | Histogram (H). A new histogram window is created for every image; this window shows a plot representing the intensity levels in the horizontal axis (from 0 to 255 in these images), and the number of pixels for each intensity level in the vertical axis:

Image histogram and window/level parameters

happy_face and tuberculosis_sample images with their corresponding histograms. Note that, as the tuberculosis image is a 16-bit image, the pixel values have been grouped (Bins: 256).

For every histogram, descriptive statistics are shown: mean, standard deviation, mode, minimum, and maximum. Notice that the value labeled as count corresponds to the summation of all values for every intensity value, and consequently corresponds to the total number of pixels in every image (for instance, the image happy_face has 710 * 1068 = 758280 pixels, which is the count value for its histogram). When you move the mouse pointer over the histogram, the intensity and the pixel count (the value of the histogram, for that intensity) corresponding to that position are displayed.

Now, let's take a look at the shape of these two histograms. For the image happy_face, the majority of the pixels have intermediate intensity values (different shades of gray in the image). This is represented in the histogram as one mode, one peak, surrounded by high histogram values. The histogram shows low values at the beginning and at the end of the plot, because there are almost no pixels that have very high or very low values. The tuberculosis_sample image, on the other side, has most of its pixels with dark values, corresponding to the background or the big rounded area with dark gray intensities. Consequently, its histogram has two modes on the left of the plot (where the dark pixels are represented), and since the bright pixels are so few, the right of the histogram is almost empty.

When we want to plot the histogram of a stack, ImageJ will ask if we want to include all the slices in the histogram calculation. In that case, all voxels (all pixels in all the slices of the stack) will be used to plot the histogram. But we may want to evaluate how the intensity is distributed in every slice. For that purpose, you can use the Live button that you will find in the Histogram plot. When it is activated, the histogram will correspond only to the current slice, and will be dynamically updated when you change it. Test this feature on sample image T1 head. Open the image, display the histogram (Analyze | Histogram (H)), and click on Yes when asked to include all the 129 images. The plotted histogram is calculated from the whole stack. Now, click on the Live button and see how the histogram is updated when you change the slice in the stack.

Image histograms are used to explore the intensity distribution in the image in order to transform the intensity values. We could select which intensity range we want to display in the screen, and all values outside of the range will be represented with the minimum or maximum intensity. The original values are not modified; it is the intensity mapping, which is performed when every original value is assigned a specific gray or color value to display in the screen, that is changed. Open the sample image named CT to exemplify this concept. If you plot the histogram, you will see that the original image has values from -719 to 1402. This 2121 intensity values must be mapped to 256 gray levels in the computer screen.

While examining the histogram, you will notice that many intensity values have almost no pixel counts. Instead of using gray levels to represent pixels that are almost never present in the image, we could use all our possible 256 gray levels to represent the area of the histogram that has information content.

How do we modify the intensity range from the original image that is displayed in the screen using the 256 gray levels? ImageJ offers several alternatives. Select the window containing the CT image and go to Image | Adjust | Brightness/Contrast... (Ctrl + Shift + C). Image intensities from -200 to 300 are being mapped to all the 256 gray levels in the screen. All values from -719 (image minimum) to -200 will be black in the image window, and all values from 300 to 1402 (image maximum) will be white. The B&C window also shows the histogram so we can check which area is being mapped in the screen. If we modify the minimum and maximum values, the intensity mapping will be updated, and if we click on the Auto button, ImageJ will optimize the values in order to allow only a small percentage of the pixels to be saturated (displayed as black or white). The Brightness and Contrast sliders are a different way of modifying the intensity values displayed; the first one moves the whole range left or right over the histogram, and the latter increases or decreases the range itself:

Image histogram and window/level parameters

Image sample CT.dcm with histogram and Brightness/Contrast (B&C) windows opened. B&C shows that all pixels below -200 are displayed in black, pixels above 300 will be white, and the range in between are mapped to gray values from 0 to 255 in the image window.

Window and Level (available from Image | Adjust | Window/Level...) is a tool similar to the Brightness and Contrast sliders. The Level is the center of the intensity range that is displayed on the screen, and Window is the width of that range. For instance, if you click on the Reset button in the Window/Level window, the Level is placed in the center of the histogram, and the Window width is the whole image range.

Tip

You may have been asking yourself why ImageJ selected the specific range from -200 to 300 when we opened the CT sample image. This range was stored in the image metadata as window width and level values. You can check it by selecting the CT image window and going to Image | Show Info... (I). A lot of fields are displayed (coming from the original DICOM file), and if you look at the end of the list you will find these values:

  • 0028,1050 Window Center: 50
  • 0028,1051 Window Width: 500

These values correspond to an intensity range centered at 50, that starts at 50 - (500 / 2) and ends at 50 + (500 / 2). Voilà!

Another interesting way to adjust the displayed intensities to the range that maximizes the visualization of an area of the image is by drawing a selection over that area (for instance, using the rectangular selection tool, which is the leftmost button in the toolbar, and then clicking and dragging over the desired area), and then clicking on the Auto button in the B&C window. ImageJ will show the histogram of that area and adjust the displayed range. With this method, we can focus our display parameters on different areas:

Image histogram and window/level parameters

Sample image CT.dcm displayed with four intensity adjustments automatically calculated from four selections (in yellow over every image). The histogram is different for every case because it corresponds to the selection. The selections are whole image (top left), teeth (top right), lung (bottom left), and arm bone (bottom left).

Tip

Adjusting brightness and contrast in color images is a process similar to the one described. If you want to modify the Red, Green, and Blue channels independently, use Image | Adjust | Color Balance... to select the one you want to adjust.

Thresholding

Until now we have learned what image types ImageJ can handle, how to read these images on how their values are displayed in the computer screen. But at the beginning of this book, we have told you that ImageJ has more to do with quantification than with display, so you may be asking when we will start obtaining some information from our images. In this section, we are going to learn how to segment a digital image using intensity thresholding. Segmentation is the process of obtaining which pixels in the image belong to one or several regions of interest. With intensity thresholding, we can do this labeling depending on the intensity value of each pixel. We have learned in the previous section that the histogram plots the intensity distribution in the image, so it is going to be a good tool for intensity thresholding.

Intensity thresholding is simple. We will classify pixels as belonging to a segmented region of interest or not, depending on if their intensity value is inside a certain range. It is difficult to select this range just by taking a look at the image, but if we can interactively modify this range while displaying the resulting segmentation, it is much easier. This can be done using Image | Adjust | Threshold... (Ctrl + Shift + T). Let's test it on the tuberculosis_sample.tif test image. The threshold interface will automatically select a range (two threshold values) and the resulting segmentation will be the pixels within that range. The default mode to display the result is named Over/Under: those pixels with values below the lower threshold are displayed in blue, and the ones above the higher threshold in green. You can change this option to Red (segmented pixels in red) or B&W (segmented pixels in black, remaining in white, which is the way masks are visualized).

Tip

Your selection in the way ImageJ presents thresholding results (Over/Under, Red, or B&W) will be saved in ImageJ.cfg, so that every time you reopen ImageJ, the last used mode will be selected.

There are several methods to calculate the optimal threshold in terms of classification. These methods minimize parameters such as intraclass variance (the variance of the intensity values of the segmented pixels or background pixels). ImageJ has 16 of these automatic threshold calculation methods implemented. Every time you select one of them, threshold values are modified according to that method, and your manual values are lost. When you click on Apply, the segmented pixels will be assigned a value of 255, the remaining will be set to 0. You can see the different segmentation display modes in the tuberculosis image. The lower and upper threshold limits are 47 and 80, respectively, so it is segmenting the bright regions of the image, but leaving out the brightest spots. You will need to check the Dark Background checkbox in the Threshold dialog.

Thresholding

Different visualization modes during the thresholding process: Red (left), B&W (center), and Over/Under (right).

Tip

Despite being a 16-bit image, the maximum gray value in tuberculosis_sample.tif is 255. This file could have been stored as an 8-bit image, but this allows us to show that the bit depth only defines the maximum and minimum theoretical values a pixel may have, but the actual contents of the image do not need to use all of them and may in fact, be constrained to a small range.

It is not necessary to lose your original image if what you wanted was to make some measurements in the segmented region. Open the tuberculosis image again (in case, you have overwritten it with your thresholding result). Go to Analyze | Set Measurements.... In this interface, you can select the measures you are interested in (Area, Min & max gray value, Perimeter...). If you check the Limit to threshold option, these measures will be calculated for the segmented pixels only. Now, repeat the thresholding process, and without closing the threshold interface, perform measures on your region (with Analyze | Measure (Ctrl + M)). If you repeat this process with different thresholds, you will obtain different measures.

The thresholding process can also be applied to stacks. In that case, you could use the whole stack histogram, or the one corresponding to the current slice. The following snapshot corresponds to the result of Otsu's automatic thresholding on the T1 head stack:

Thresholding

Otsu's automatic threshold on the T1 head stack. Segmented pixels are shown in red.

Image resizing

The zoom options that we explained at the beginning of the chapter allow you to focus on certain regions of the image, but do not modify its contents. However, on some occasions, it may make sense to resize the image, making it actually bigger or smaller. There are two different ways you can accomplish it.

The first one involves resizing the image, and expanding or shrinking the pixel values so that they fit into the new dimensions. This is accomplished by selecting Image | Adjust | Size…:

Image resizing

In the dialog that appears, you can select the new image dimensions. If the Constrain aspect ratio option is checked, you only need to set the new width, and the height will be automatically filled. If it is bigger than the original image, the contents will be expanded using the selected interpolation.

The other option involves changing the image canvas. This is done using Image | Adjust | Canvas Size…:

Image resizing

So, what is the difference between these two methods? With the first one, the contents of the image are accommodated inside the new dimensions. With the second one, the image area is expanded or shrunk, but the image size is the same. If you make the area bigger, the original image will be placed in the selected position, unmodified, and the added voxels will be filled with zero values. If you make the area smaller, the image will be cropped, but not resized. The following image shows the difference between both the methods. We have resized one of the tuberculosis images and have expanded its width to 300 pixels from an original value of 202:

Image resizing

Left: original image. Center: resized image. Right: resized canvas.

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

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