Sharpening an Image

Sharpening an image increases the contrast between bright and dark regions to bring out features.

The sharpening process is basically the application of a high pass filter to an image. The following array is a kernel for a common high pass filter used to sharpen an image:

Sharpening_an_Image-46.jpg

Note
The above array is an example of one possible kernel for a sharpening filter. Other filters may include more weighting for the center point.

As mentioned in the filtering section of this chapter, filters can be applied to images in IDL with the CONVOL function. See High Pass Filtering for more information on high pass filters.

The following example shows how to use IDL's CONVOL function and the above high pass filter kernel to sharpen an image. This example uses the Magnetic Resonance Image (MRI) of a human knee contained within the mr_knee.dcm file in the examples/data directory. Within the original knee MRI, some information is nearly as dark as the background. This image is sharpened to display these dark areas with improved contrast. Complete the following steps for a detailed description of the process.

Example Code
See sharpening.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering sharpening at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT sharpening.pro.

  1. Import the image from the mr_knee.dcm file:
  2. file = FILEPATH('mr_knee.dcm', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    image = READ_DICOM(file) 
    imageSize = SIZE(image, /DIMENSIONS) 
    
  3. Initialize the display:
  4. DEVICE, DECOMPOSED = 0 
    LOADCT, 0 
    
  5. Create a window and display the original image:
  6. WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ 
       TITLE = 'Original Knee MRI' 
    TVSCL, image 
     

    The following figure shows the original image.

    Figure 8-32: Original Knee MRI

    imgcontr32.gif

  7. Create a kernel for a sharpening (high pass) filter:
  8. kernelSize = [3, 3] 
    kernel = REPLICATE(-1./9., kernelSize[0], kernelSize[1]) 
    kernel[1, 1] = 1. 
    
  9. Apply the filter to the image:
  10. filteredImage = CONVOL(FLOAT(image), kernel, $ 
       /CENTER, /EDGE_TRUNCATE) 
    
  11. Create another window and display the resulting filtered image:
  12. WINDOW, 1, XSIZE = imageSize[0], YSIZE = imageSize[1], $ 
       TITLE = 'Sharpen Filtered Knee MRI' 
    TVSCL, filteredImage 
     

    The following figure shows the results of applying the sharpening (high pass) filter. Pixels that differ dramatically in contrast with surrounding pixels are brightened.

    Figure 8-33: Sharpen FIltered Knee MRI

    imgcontr33.gif

  13. Create another window and display the combined images:
  14. WINDOW, 2, XSIZE = imageSize[0], YSIZE = imageSize[1], $ 
       TITLE = 'Sharpened Knee MRI' 
    TVSCL, image + filteredImage 
     

    The following figure shows the combination of the sharpened and original images. This image is sharper, containing more information within several regions, especially the tips of the bones.

    Figure 8-34: Sharpened Knee MRI

    imgcontr34.gif