|
Image Processing : Transforming Between Domains |
|
Images do not have to be completely transformed into the frequency domain. Some transformations only partially convert an image into the frequency domain. One of the most common types of these transformations is into the time-frequency or wavelet domain.
The Discrete Wavelet Transform (DWT) is used in numerical analysis to transform an image from the spatial domain to the time-frequency domain and back again. This transform is different from the FFT. The FFT decomposes an image with sines and cosines over the entire image. In contrast, the wavelet functions are applied multiple times over portions.
The image information within the time-frequency domain shows the frequency of patterns within an image, and how these patterns vary over the image. The low frequencies typically contain most of the information, which is commonly seen as a peak (spike) of data within the time-frequency domain. The information at the high frequencies is usually noise. The image can easily be altered within the time-frequency domain to remove the noise.
The following sections introduce the concepts needed to work with images and Discrete Wavelet Transforms (DWTs):
The wavelet transformation process is the basis for many image compression algorithms. See Removing Noise with the Wavelet Transform for an example of how wavelets can be used to compress data and remove noise.
When an image is transformed with a DWT from the spatial domain to the time-frequency domain, the transformation process is referred to as a forward DWT. The forward DWT process can be performed with IDL's WTN function.
The low frequencies usually contain most of the useful information within the image, which is shown by the peak (spike) of data around the origin within the time-frequency domain. If the image does not contain any background noise, the rest of the data frequency values are very close to zero. However, the results of the WTN function have a very wide range. An initial display may not show any variations from zero, but a smaller surface range will show that the image does actually contain background noise. Since scaling a range can sometimes be quite arbitrary, different methods are used. See Displaying Images in the Time-Frequency Domain for more information on displaying the results of a forward DWT.
The following example shows how to use IDL's WTN function to compute a forward DWT. This example uses the first image within the abnorm.dat file, which is in the examples/data directory. Complete the following steps for a detailed description of the process.
| Example Code See forwardwavelet.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
abnorm.dat file:
imageSize = [64, 64]
file = FILEPATH('abnorm.dat', $
SUBDIRECTORY = ['examples', 'data'])
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.
waveletTransform = WTN(image, 20)
The Coef argument is set to 20 to specify 20 wavelet filter coefficients to provide the most efficient wavelet estimate possible. Less wavelet filter coefficients can be used with larger images to decrease computation time.
WINDOW, 1, TITLE = 'Wavelet: Transform' SHADE_SURF, waveletTransform, /XSTYLE, /YSTYLE, $ /ZSTYLE, TITLE = 'Transform of Image', $ XTITLE = 'Horizontal Number', $ YTITLE = 'Vertical Number', $ ZTITLE = 'Amplitude', CHARSIZE = 1.5
The following figure shows the wavelet transform. The data at the high frequencies seems to be close to zero, but the peak (spike) in the z range is so large that a closer look is needed.
![]() |
WINDOW, 2, TITLE = 'Wavelet: Transform (Closer Look)' SHADE_SURF, waveletTransform, /XSTYLE, /YSTYLE, $ /ZSTYLE, TITLE = 'Transform of Image', $ XTITLE = 'Horizontal Number', $ YTITLE = 'Vertical Number', ZTITLE = 'Amplitude', CHARSIZE = 1.5, $ ZRANGE = [0., 200.]
The following figure shows the wavelet transform with the z-axis ranging from 0 to 200. A closer looks shows that the image does contain background noise.
Within the time-frequency domain, the range of values from the peak to the spurious high frequency data is extreme. The logarithmic scale is applied to retain the shape of the surface, but reduce its range. Since the logarithmic scale only applies to positive values, you should first compute the power spectrum, which is the absolute value squared of the transform.
The following example shows how to display the results of IDL's WTN function. This example also uses the first image within the abnorm.dat file, which is in the examples/data directory. Complete the following steps for a detailed description of the process.
| Example Code See displaywavelet.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
abnorm.dat file:
imageSize = [64, 64]
file = FILEPATH('abnorm.dat', $
SUBDIRECTORY = ['examples', 'data'])
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.
waveletTransform = WTN(image, 20)
The Coef argument is set to 20 to specify 20 wavelet filter coefficients to provide the most efficient wavelet estimate possible. Less wavelet filter coefficients can be used with larger images to decrease computation time.
powerSpectrum = ABS(waveletTransform)^2
scaledPowerSpect = ALOG10(powerSpectrum)
WINDOW, 1, TITLE = 'Wavelet Power Spectrum: ' + $ 'Logarithmic Scale (surface)' SHADE_SURF, scaledPowerSpect, /XSTYLE, /YSTYLE, /ZSTYLE, $ TITLE = 'Log-scaled Power Spectrum of Image', $ XTITLE = 'Horizontal Number', $ YTITLE = 'Vertical Number', $ ZTITLE = 'Log(Squared Amplitude)', CHARSIZE = 1.5
The following figure shows the log-scaled power spectrum of the wavelet transform as a surface.
![]() |
WINDOW, 2, XSIZE = displaySize[0], YSIZE = displaySize[1], $ TITLE = 'Wavelet Power Spectrum: Logarithmic Scale (image)' TVSCL, CONGRID(scaledPowerSpect, displaySize[0], $ displaySize[1])
The following figure shows the log-scaled power spectrum as an image. Most of the signal is located near the origin (the lower left of the power spectrum image). This data is shown as bright pixels at the origin. The noise appears in the rest of the image.
After manipulating an image within the time-frequency domain, you will need to transform it back to the spatial domain. This transformation process is referred to as an inverse DWT. The inverse DWT process can be performed with IDL's WTN function by setting the INVERSE keyword.
The following example shows how to use IDL's WTN function to compute an inverse DWT. This example uses the first image within the abnorm.dat file, which is in the examples/data directory. The image is not manipulated while it is in the time-frequency domain to show that no data is lost when using the DWT. However, manipulating data within the time-frequency domain is a useful way to compress data and remove background noise from an image, as shown in Removing Noise with the Wavelet Transform. Complete the following steps for a detailed description of the process.
| Example Code See inversewavelet.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
abnorm.dat file:
imageSize = [64, 64]
file = FILEPATH('abnorm.dat', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_BINARY(file, DATA_DIMS = imageSize)
displaySize = 2*imageSize
DEVICE, DECOMPOSED = 0 LOADCT, 0
waveletTransform = WTN(image, 20)
The Coef argument is set to 20 to specify 20 wavelet filter coefficients to provide the most efficient wavelet estimate possible. Fewer wavelet filter coefficients can be used with larger images to decrease computation time.
powerSpectrum = ABS(waveletTransform)^2
scaledPowerSpect = ALOG10(powerSpectrum)
; Create a window and display the transform. WINDOW, 0, XSIZE = displaySize[0], YSIZE = displaySize[1], $ TITLE = 'Power Spectrum Image' TVSCL, CONGRID(scaledPowerSpect, displaySize[0], $ displaySize[1])
The following figure shows the log-scaled power spectrum of the image.
![]() |
waveletInverse = WTN(waveletTransform, 20, /INVERSE)
WINDOW, 1, XSIZE = displaySize[0], YSIZE = displaySize[1], $ TITLE = 'Wavelet: Inverse Transform' TVSCL, CONGRID(waveletInverse, displaySize[0], $ displaySize[1])
The inverse transform is the same as the original image. No image data is lost when transforming an image to and from the time-frequency domain.
![]() |
This example uses IDL's WTN function to remove noise from an image. The image comes from the abnorm.dat file found in the examples/data directory. The first display contains the original image and its wavelet transform. The noise is very evident in the image. A surface of the transform helps to determine beyond which point the noise occurs. Only the important data is kept and noise is replaced by zero values. The inverse transform is then applied, resulting in a cleaner image. Complete the following steps for a detailed description of the process.
| Example Code See removingnoisewithwavelet.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
abnorm.dat file:
imageSize = [64, 64]
file = FILEPATH('abnorm.dat', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_BINARY(file, DATA_DIMS = imageSize)
displaySize = 2*imageSize
DEVICE, DECOMPOSED = 0 LOADCT, 0
WINDOW, 0, XSIZE = 2*displaySize[0], $ YSIZE = displaySize[1], $ TITLE = 'Original Image and Power Spectrum' TVSCL, CONGRID(image, displaySize[0], $ displaySize[1]), 0
waveletTransform = WTN(image, 20)
The Coef argument is set to 20 to specify 20 wavelet filter coefficients to provide the most efficient wavelet estimate possible. Fewer wavelet filter coefficients can be used with larger images to decrease computation time.
TVSCL, CONGRID(ALOG10(ABS(waveletTransform^2)), $ displaySize[0], displaySize[1]), 1
The following figure shows the original image and its power spectrum within the time-frequency domain.
![]() |
croppedTransform = FLTARR(imageSize[0], imageSize[1]) croppedTransform[0, 0] = waveletTransform[0:(imageSize[0]/2), $ 0:(imageSize[1]/2)]
WINDOW, 1, XSIZE = 2*displaySize[0], $ YSIZE = displaySize[1], $ TITLE = 'Power Spectrum of Cropped Transform and Results' TVSCL, CONGRID(ALOG10(ABS(croppededTransform^2)), $ displaySize[0], displaySize[1]), 0, /NAN
inverseTransform = WTN(maskedTransform, 20, /INVERSE)
TVSCL, CONGRID(inverseTransform, displaySize[0], $ displaySize[1]), 1
The following figure shows the power spectrum of the cropped transform and its resulting inverse transform. The cropping process shows that only one quarter of the data was needed to reconstruct the image. The image is compressed by a 4:1 ratio.
IDL Online Help (March 06, 2007)