Transforming Between Domains with Wavelets

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.

Transforming to the Time-Frequency Domain

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. Run the example procedure by entering forwardwavelet at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT forwardwavelet.pro.

  1. Import the first image from the abnorm.dat file:
  2. imageSize = [64, 64] 
    file = FILEPATH('abnorm.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    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 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 7-12: Original Gated Blood Pool Image

    imgtrans24.gif

  9. With the WTN function, transform the image into the wavelet domain:
  10. 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.

  11. Create another window and display the wavelet transform:
  12. 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.

    Figure 7-13: Wavelet Transform of Gated Blood Pool Image

    imgtrans25.gif

  13. Create another window and display the wavelet transform, scaling the data (z) range from 0 to 200:
  14. 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.

    Figure 7-14: Wavelet Transform of Image Scaled Between 0 and 200

    imgtrans26.gif

Displaying Images in the Time-Frequency Domain

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. Run the example procedure by entering displaywavelet at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT displaywavelet.pro.

  1. Import the first image from the abnorm.dat file:
  2. imageSize = [64, 64] 
    file = FILEPATH('abnorm.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    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 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 7-15: Original Gated Blood Pool Image

    imgtrans27.gif

  9. Transform the image into the time-frequency domain.
  10. 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.

  11. Compute the power spectrum.
  12. powerSpectrum = ABS(waveletTransform)^2 
    
  13. Apply a logarithmic scale to the power spectrum:
  14. scaledPowerSpect = ALOG10(powerSpectrum) 
    
  15. Create another window and display the log-scaled power spectrum as a surface:
  16. 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.

    Figure 7-16: Log-scaled Wavelet Power Spectrum of Image (as a surface)

    imgtrans28.gif

  17. Create another window and display the log-scaled power spectrum as an image:
  18. 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.

    Figure 7-17: Log-scaled Wavelet Power Spectrum of Image (as am image)

    imgtrans29.gif

Transforming from the Time-Frequency Domain

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. Run the example procedure by entering inversewavelet at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT inversewavelet.pro.

  1. Import the first image from the abnorm.dat file:
  2. imageSize = [64, 64] 
    file = FILEPATH('abnorm.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    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. With the WTN function, transform the image into the wavelet domain:
  8. 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.

  9. Compute the power spectrum:
  10. powerSpectrum = ABS(waveletTransform)^2 
    
  11. Apply a logarithmic scale to the power spectrum:
  12. scaledPowerSpect = ALOG10(powerSpectrum) 
    
  13. Create a window and display the log-scaled power spectrum as an image:
  14. ; 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.

    Figure 7-18: Log-scaled Wavelet Power Spectrum of Image

    imgtrans30.gif

  15. With the WTN function, transform the wavelet domain data back to the original image (obtain the inverse transform):
  16. waveletInverse = WTN(waveletTransform, 20, /INVERSE) 
    
  17. Create another window and display the inverse transform as an image:
  18. 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.

Figure 7-19: Inverse of the Wavelet Transform of the Gated Blood Pool Image

imgtrans31.gif

Removing Noise with the Wavelet Transform

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. Run the example procedure by entering removingnoisewithwavelet at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT removingnoisewithwavelet.pro.

  1. Import the first image from the abnorm.dat file:
  2. imageSize = [64, 64] 
    file = FILEPATH('abnorm.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    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 image:
  8. WINDOW, 0, XSIZE = 2*displaySize[0], $ 
       YSIZE = displaySize[1], $ 
       TITLE = 'Original Image and Power Spectrum' 
    TVSCL, CONGRID(image, displaySize[0], $ 
       displaySize[1]), 0 
    
  9. Determine the wavelet transform of the image:
  10. 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.

  11. Display the power spectrum of the transform:
  12. 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.

    Figure 7-20: Gated Blood Pool Image and Its Wavelet Power Spectrum

    imgtrans32.gif

  13. Crop the transform to only include the quadrant of data closest to the spike of low frequency in the lower-left corner:
  14. croppedTransform = FLTARR(imageSize[0], imageSize[1]) 
    croppedTransform[0, 0] = waveletTransform[0:(imageSize[0]/2), 
    $ 
       0:(imageSize[1]/2)] 
    
  15. Create another window and display the power spectrum of the cropped transform as an image:
  16. 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 
    
  17. Apply the inverse transformation to the masked power spectrum:
  18. inverseTransform = WTN(maskedTransform, 20, /INVERSE) 
    
  19. Display results of the inverse transform:
  20. 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.

    Figure 7-21: Masked Wavelet Power Spectrum and Its Resulting Inverse Transform

    imgtrans35.gif