Image Processing : Contrasting and Filtering |
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:
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. |
abnorm.dat
file:file = FILEPATH('abnorm.dat', $ SUBDIRECTORY = ['examples', 'data']) imageSize = [64, 64] image = READ_BINARY(file, DATA_DIMS = imageSize)
displaySize = 2*imageSize
DEVICE, DECOMPOSED = 0 LOADCT, 0
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.
transform = SHIFT(FFT(image), (imageSize[0]/2), $ (imageSize[1]/2))
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.
|
mask = HANNING(imageSize[0], imageSize[1]) maskedTransform = transform*mask
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.
|
inverseTransform = FFT(SHIFT(maskedTransform, $ (imageSize[0]/2), (imageSize[1]/2)), /INVERSE)
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.
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. |
abnorm.dat
file:file = FILEPATH('abnorm.dat', $ SUBDIRECTORY = ['examples', 'data']) imageSize = [64, 64] image = READ_BINARY(file, DATA_DIMS = imageSize)
displaySize = 2*imageSize
DEVICE, DECOMPOSED = 0 LOADCT, 0
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.
filteredImage = LEEFILT(image, 1)
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.
IDL Online Help (March 06, 2007)