Chest radio-graphs are an essential step in the diagnosis of many diseases localized in the chest or lungs. Enhancing these images through spatial or histogram transforms are a common practice throughout the medical industry. However developing and under-developed countries often still use x-ray photographic films because they have not been exposed to such technologies in many cases.
But with the advent of low price computing devices such as smartphones and micro computers, it is now possible to just click a picture of an x-ray and analyse it for various features that might indicate diseases. In this article we shall discuss three such image transforms with increasing clarity of those x-ray images without going deep into the mathematical details and discuss if such pre-processing actually helps in image classification tasks if applied to a neural network.
Let’s import an image using open-cv’s imread function:
img = cv2.imread(os.path.join(path,'x-ray.jpeg'),0)
plt.imshow(img,cmap = 'gray')
Fig 1: Normal Image
The above is an x-ray of a 5 year old male with normal, healthy lungs. But the bronchioles appear diffused and a layman may not even see details of the lungs.
One might guess we need contrast correction here to look for more details. So let’s apply a gamma transformation and observe the results.
In gamma transformation we first normalize the pixel values and then raise the pixel values to a power greater than 1 to improve contrast.
gamma = numpy.power(img,1.5)
plt.imshow((gamma),cmap = 'gray')
Fig 2: Gamma Correction
The contrast between lungs and bronchioles have improved and one may notice finer details.
Now we take it a step further and try Histogram Equalization.
In any image, the pixel values are limited to a specific range only, from the way the image was formed. We can visualize that from the histogram of pixel intensities of the image. An image histogram shows how many spatial pixels are actually assigned to each pixel value. Let’s understand that by looking at the histogram of the original image and compare it to the histogram equalized version.
For this we use the equalizeHist() function in open-cv.
histr = cv2.calcHist([img],[0],None,[256],[0,256])
plt.plot(histr)
Fig 3: Original Image Histogram
his = cv2.equalizeHist(img)
histr = cv2.calcHist([his],[0],None,[256],[0,256])
plt.plot(histr)
Fig 4:Histogram Equalized version
In the original image, a lot of pixels are concentrated in the values between 150 and 200. What equalization does is, it re-assigns pixels to new values so that a greater range of values is covered, and theoretically this leads to making features ‘more visible’.
Fig 5: Histogram Equalized image
Comparing the figure 2 and figure 5, it is true that the contrast has improved just by reassigning pixel values. But we may also lose some information along the rib cage due to the over-brightness.
Is there any algorithm that performs even better than this ?
Contrast Limiting Adaptive Histogram Equalization (CLAHE) comes to our rescue!
It first divides the image into grids of 8 x 8 squares and applies HE on them individually. If noise is present in those grids, it will be amplified. Contrast Limiting is applied to avoid noise amplification. If a histogram bin is above some limit, those pixels are clipped and distributed uniformly to other bins.
Further to remove unwanted features and noise, bi-linear interpolation is applied, which is just a fancy term for weighted average of adjacent pixels. Let’s take a look at the CLAHE image:
clahe = cv.createCLAHE(clipLimit = 5)
final_img = clahe.apply(img)
plt.imshow(final_img,cmap = 'gray')
Fig 6: CLAHE Image
There is massive improvement in feature detailing, especially along the spine, rib-cage and bronchioles, without an abrupt increase in brightness or contrast.
The intention of this article was to help the reader gain intuition about the applications of image processing in biomedical images and early diagnosis of potentially life threatening diseases.
It is totally possible to have such functionality in the form of a smartphone app in developing countries where doctors still rely on raw x-ray films for radiology diagnosis.
Comments