Wavelet Toolbox Previous page   Next Page

Two-Dimensional Analysis Using the Command Line

In this example we'll show how you can use two-dimensional wavelet analysis to compress an image efficiently without sacrificing its clarity.

  1. Load an image.
  1. From the MATLAB prompt, type

  1. Display the image. Type
  2. Convert an indexed image to a grayscale image.
  1. If the colormap is smooth, the wavelet transform can be directly applied to the indexed image; otherwise the indexed image should be converted to grayscale format. For more information, see Wavelets: Working with Images.

    Since the colormap is smooth in this image, you can now perform the decomposition.

  1. Perform a single-level wavelet decomposition.
  1. To perform a single-level decomposition of the image using the bior3.7 wavelet, type

    This generates the coefficient matrices of the level-one approximation (cA1) and horizontal, vertical and diagonal details (cH1,cV1,cD1, respectively).

  1. Construct and display approximations and details from the coefficients.
  1. To construct the level-one approximation and details (A1, H1, V1, and D1) from the coefficients cA1, cH1, cV1, and cD1, type

    or

    To display the results of the level 1 decomposition, type

  1. Regenerate an image by single-level Inverse Wavelet Transform.
  1. To find the inverse transform, type

    This reconstructs or synthesizes the original image from the coefficients of the level 1 approximation and details.

  1. Perform a multilevel wavelet decomposition.
  1. To perform a level 2 decomposition of the image (again using the bior3.7 wavelet), type

    where X is the original image matrix, and 2 is the level of decomposition.

    The coefficients of all the components of a second-level decomposition (that is, the second-level approximation and the first two levels of detail) are returned concatenated into one vector, C. Argument S is a bookkeeping matrix that keeps track of the sizes of each component.

  1. Extract approximation and detail coefficients.
  1. To extract the level 2 approximation coefficients from C, type

    To extract the first- and second-level detail coefficients from C, type

    or

    where the first argument ('h', 'v', or 'd') determines the type of detail (horizontal, vertical, diagonal) extracted, and the last argument determines the level.

  1. Reconstruct the Level 2 approximation and the Level 1 and 2 details.
  1. To reconstruct the level 2 approximation from C, type

    To reconstruct the level 1 and 2 details from C, type

  1. Display the results of a multilevel decomposition.

  1. To display the results of the level 2 decomposition, type

  1. Reconstruct the original image from the multilevel decomposition.
  1. To reconstruct the original image from the wavelet decomposition structure, type

    This reconstructs or synthesizes the original image from the coefficients C of the multilevel decomposition.

  1. Compress the image and display it.
  1. To compress the original image X, use the ddencmp command to calculate the default parameters and the wdencmp command to perform the actual compression. Type

    Note that we pass in to wdencmp the results of the decomposition (C and S) we calculated in Step 7. We also specify the bior3.7 wavelets, because we used this wavelet to perform the original analysis. Finally, we specify the global thresholding option 'gbl'. See ddencmp and wdencmp reference pages for more information about the use of these commands.

    To view the compressed image side by side with the original, type

    These returned values tell, respectively, what percentage of the wavelet coefficients was set to zero and what percentage of the image's energy was preserved in the compression process.

    Note that, even though the compressed image is constructed from only about half as many nonzero wavelet coefficients as the original, there is almost no detectable deterioration in the image quality.


Previous page  Two-Dimensional Discrete Wavelet Analysis Two-Dimensional Analysis Using the Graphical Interface Next page

© 1994-2005 The MathWorks, Inc.