Previous Image Processing : Contrasting and Filtering Next

Removing Noise

When a device (such as a camera or scanner) captures an image, the device sometimes adds extraneous noise to the image. This noise must be removed from the image for other image processing operations to return valuable results. Some noise can simply be removed by smoothing an image or masking it within the frequency domain, but most noise requires more involved filtering, such as windowing or adaptive filters. The following example shows how to use windowing and adaptive filters to remove noise from an image within IDL:

Windowing to Remove Noise

Within the frequency domain, a filter is applied to an image by multiplying the FFT of that image by the FFT of the filter. When the FFT of a image is multiplied by the FFT of a filter to perform convolution, this process is known as windowing.

The DIST and HANNING functions are examples of windowing filters already transformed into the frequency domain. Windowing with the DIST function has the same effect as applying a high pass filter. The high frequency information is retained, while the effect of the low frequency information is decreased. In contrast, the HANNING function retains the low frequency information. The results of the HANNING function are similar to a mask used to remove noise in an image. The HANNING function can be used to create either a Hanning or Hamming window. Although the DIST and the HANNING functions perform different filtering tasks, these filters are applied the same way, so only one example is provided in this section.

Windowing is different than simply using a mask within the frequency domain. Using a mask omits information within the image, while windowing retains the information, but decreases its effect on the image. See Removing Noise with the FFT for more information on using a mask to remove noise from an image.

The following example shows how to use the HANNING function when windowing an image to remove background noise. This example uses the first image within the abnorm.dat file in the examples/data directory. Complete the following steps for a detailed description of the process.


Example Code
See removingnoisewithhanning.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example.

  1. Import the image from the abnorm.dat file:
  2. file = FILEPATH('abnorm.dat', $  
       SUBDIRECTORY = ['examples', 'data'])  
    imageSize = [64, 64]  
    image = READ_BINARY(file, DATA_DIMS = imageSize)  
    

     

  3. Initialize a display size parameter to resize the image when displaying it:
  4. displaySize = 2*imageSize  
    

     

  5. Initialize the display:
  6. DEVICE, DECOMPOSED = 0  
    LOADCT, 0  
    

     

  7. Create a window and display the original image:
  8. WINDOW, 0, XSIZE = displaySize[0], $  
       YSIZE = displaySize[1], $  
       TITLE = 'Original Image'  
    TVSCL, CONGRID(image, displaySize[0], displaySize[1])  
    

     

    The following figure shows the original image.

     

    Figure 8-36: Original Gated Blood Pool Image

    Figure 8-36: Original Gated Blood Pool Image

     

  9. Determine the forward Fourier transformation of the image:
  10. transform = SHIFT(FFT(image), (imageSize[0]/2), $  
       (imageSize[1]/2))  
    

     

  11. Create another window and display the power spectrum:
  12. WINDOW, 1, TITLE = 'Surface of Forward FFT'  
    SHADE_SURF, (2.*ALOG10(ABS(transform))), /XSTYLE, /YSTYLE, $  
       /ZSTYLE, TITLE = 'Power Spectrum', $  
       XTITLE = 'Mode', YTITLE = 'Mode', $  
       ZTITLE = 'Amplitude', CHARSIZE = 1.5  
    

     

    The following figure shows the power spectrum of the original image. Noise within the image is shown as small peaks.

     

    Figure 8-37: Power Spectrum of the Gated Blood Pool Image

    Figure 8-37: Power Spectrum of the Gated Blood Pool Image

     

  13. Use a Hanning mask to filter out the noise:
  14. mask = HANNING(imageSize[0], imageSize[1])  
    maskedTransform = transform*mask  
    

     

  15. Create another window and display the masked power spectrum:
  16. WINDOW, 2, TITLE = 'Surface of Filtered FFT'  
    SHADE_SURF, (2.*ALOG10(ABS(maskedTransform))), $  
       /XSTYLE, /YSTYLE, /ZSTYLE, TITLE = 'Masked Power 
    Spectrum', $  
       XTITLE = 'Mode', YTITLE = 'Mode', $  
       ZTITLE = 'Amplitude', CHARSIZE = 1.5  
    

     

    The following figure shows the results of applying the Hanning window. The Hanning window gradually smooths the high frequency peaks within the image.

     

    Figure 8-38: Masked Power Spectrum of the Gated Blood Pool Image

    Figure 8-38: Masked Power Spectrum of the Gated Blood Pool Image

     

  17. Apply the inverse transformation to the masked frequency domain image:
  18. inverseTransform = FFT(SHIFT(maskedTransform, $  
       (imageSize[0]/2), (imageSize[1]/2)), /INVERSE)  
    

     

  19. Create another window and display the results of the inverse transformation:
  20. WINDOW, 3, XSIZE = displaySize[0], $  
       YSIZE = displaySize[1], $  
       TITLE = 'Hanning Filtered Image'  
    TVSCL, CONGRID(REAL_PART(inverseTransform), $  
       displaySize[0], displaySize[1])  
    

     

    The following figure shows the resulting display. Visible noise within the image has been reduced, while the valuable image data has been retained.

     

    Figure 8-39: Resulting Hanning Filtered Image

    Figure 8-39: Resulting Hanning Filtered Image

Lee Filtering to Remove Noise

Unlike the Hanning window, the Lee filter is convolved within the spatial domain. The Lee filter is an adaptive filter, which changes according to the local statistics of the current pixel. The LEEFILT routine applies the Lee filter to an image to remove background noise.

The following example shows how to use the LEEFILT function to remove background noise from an image. This example uses the first image within the abnorm.dat file in the examples/data directory. Complete the following steps for a detailed description of the process.


Example Code
See removingnoisewithleefilt.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example.

  1. Import the image from the abnorm.dat file:
  2. file = FILEPATH('abnorm.dat', $  
       SUBDIRECTORY = ['examples', 'data'])  
    imageSize = [64, 64]  
    image = READ_BINARY(file, DATA_DIMS = imageSize)  
    

     

  3. Initialize a display size parameter to resize the image when displaying it:
  4. displaySize = 2*imageSize  
    

     

  5. Initialize the display:
  6. DEVICE, DECOMPOSED = 0  
    LOADCT, 0  
    

     

  7. Create a window and display the original image:
  8. WINDOW, 0, XSIZE = displaySize[0], $  
       YSIZE = displaySize[1], $  
       TITLE = 'Original Image'  
    TVSCL, CONGRID(image, displaySize[0], displaySize[1])  
    

     

    The following figure shows the original image.

     

    Figure 8-40: Original Gated Blood Pool Image

    Figure 8-40: Original Gated Blood Pool Image

     

  9. Apply the Lee filter to the image:
  10. filteredImage = LEEFILT(image, 1)  
    

     

  11. Create another window and display the Lee filtered image:
  12. WINDOW, 1, XSIZE = displaySize[0], $  
       YSIZE = displaySize[1], $  
       TITLE = 'Lee Filtered Image'  
    TVSCL, CONGRID(filteredImage, displaySize[0], $  
       displaySize[1])  
    

     

    The following figure shows the results of applying the Lee filter, which adaptively smooths areas that contains noise.

     

    Figure 8-41: Lee Filtered Gated Blood Pool Image

    Figure 8-41: Lee Filtered Gated Blood Pool Image

     

      
    

  IDL Online Help (March 06, 2007)