1. Intensity Values
In this chapter, we'll discuss masks and filters, two techniques that emphasize important features in images. To leverage them well, you must have a thorough understanding of your data's distribution of intensity values.
2. Pixels and voxels
The building blocks of medical images are pixels and voxels.
Each of these elements has two properties: an intensity value and a location in space.
The meaning of the intensity value depends on the imaging modality. For example, pixels in this x-ray image, or radiograph, are brighter in dense tissue such as bone, because it absorbs more radiation than other types.
3. Data types and image size
The range of values allowed in an image is determined by its data type. Generally, lower-bit integers are preferred for images, since memory usage increases dramatically for larger data types. If all values in the image are positive, then unsigned integers can cover the widest range of values while taking up the least amount of memory. You will commonly see images scaled by the value 255, which is the maximum value for 8-bit unsigned integers.
You can see the difference in memory usage by calling the size attribute of the array. The foot x-ray we just saw is read by ImageIO as an 8-bit unsigned integer.
It takes up about 153 kB.
If we convert it to a 64-bit integer, however, the same information now takes up more than a megabyte of space.
4. Histograms
Histograms summarize the distribution of intensity values in an image. They bin each pixel by its value and then count each bin.
SciPy, and especially its Ndimage module, contain some essential tools for image analysis. We'll dig deeper into SciPy throughout this course.
To generate a histogram for the foot x-ray, we first import SciPy's Ndimage module as ndi.
Then, we call ndimage dot histogram() and pass in our array. The histogram() function requires us to specify values for the minimum, maximum, and the number of bins. Since our image is an 8-bit unsigned integer, our range is from 0 to 255, with 256 possible values.
This returns a 256 element vector with the count of pixels at each intensity value.
Plotting the data as a line plot reveals a highly skewed distribution, with many low values and a wider range of high values.
5. Equalization
Skewed distributions are common in medical images: background intensities are usually low and take up a lot of image space.
There are ways to modify the intensity distribution. For example, histogram equalization redistributes values based on their abundance in the image.
We can perform equalization with the aid of the cumulative distribution function, which shows the proportion of pixels that fall within a given range. Here, we can see that about half the pixels have values less than 32. To equalize the image, we could redistribute these intensity values until they are more evenly represented.
6. Equalization
Equalizing the histogram is actually pretty straightforward. First, we generate the histogram.
Then, we calculate the cumulative distribution function by taking the rolling sum of the histogram and dividing it by the total number of pixels.
Then, we apply the function to our image and rescale by 255.
Plotting the original and equalized image shows that we have increased the pixel intensities for several areas. This has made our foot stand out more clearly, but it has also given extra weight to some background areas. For biomedical applications, global equalization, such as this, should be done with caution, but the principle of redistributing intensity values is a useful one to keep in mind.
7. Let's practice!
Now, you'll investigate the intensity profile of another radiograph.