Main Content

Wavelet Image Analyzer

Decompose and visualize images

Since R2023a


The Wavelet Image Analyzer app enables you to visualize the discrete wavelet decomposition of images. With the Wavelet Image Analyzer app, you can:

  • Import images from your MATLAB® workspace or from a file

  • Specify the orthogonal or biorthogonal wavelet to use in the decomposition

  • Change the decomposition level

  • Reconstruct an image with the wavelet coefficient subbands you specify

  • Easily compare different reconstructions

  • Export the image decompositions to your MATLAB workspace

  • Generate MATLAB scripts to reproduce results in your workspace

The Wavelet Image Analyzer app supports grayscale and RGB images.

Wavelet Image Analyzer app

Open the Wavelet Image Analyzer App

  • MATLAB Toolstrip: On the Apps tab, under Image Processing and Computer Vision, click the app icon.

  • MATLAB command prompt: Enter waveletImageAnalyzer.


expand all

This example shows how to use the Wavelet Image Analyzer app to visualize the wavelet decomposition of an image. The example also shows how to compare two different image reconstructions, as well as how to generate a script to recreate the results in your workspace.

Import Data

The Wavelet Image Analyzer app can import an image from your workspace or a file. Load the xbox image into your workspace.

load xbox

Visualize Wavelet Decomposition

Open Wavelet Image Analyzer. On the Analyzer tab, click Import in the toolstrip. A window appears with a list of all the workspace variables that the app can process. Select xbox and click Import. A four-level wavelet decomposition of the image appears and the app switches to the DWT tab. In the Scenarios pane, the decomposition is named xbox1, and the method DWT identifies the kind of decomposition. By default, the decomposition is obtained using the biorthogonal bior4.4 wavelet, which has four vanishing moments each for the decomposition and reconstruction filters.

The column titles in the Decompositions pane refer to the approximation (LL) and details in three orientations: horizontal (LH), vertical (HL), and diagonal (HH). The order of the pair of letters L and H indicates the order the lowpass (L) scaling and highpass (H) wavelet filters are applied to obtain the decomposition at successive levels. For more information about the 2-D DWT algorithm, see wavedec2.

A checkbox in the Level Selection for Reconstruction pane controls whether to include those coefficients in the reconstruction. The Original-Reconstructed Image pane shows the original and reconstructed images.

To generate a new decomposition, change one of the wavelet parameters in the toolstrip:

  • Wavelet — Wavelet family

  • Number — Wavelet filter number

  • Level — Wavelet decomposition level

Changing any parameter in the toolstrip enables the Decompose button. Click Decompose.


Compare Image Decompositions

You can create new decompositions of the same signal by clicking either the Add or Duplicate buttons in the Analyzer tab toolstrip. Changes you make to the wavelet parameters apply only to the selected scenario. Similarly, the coefficients you choose to include in the reconstruction apply only to the selected scenario. To compare decompositions or reconstructions, click the desired scenario in the Scenarios pane.

In the Analyzer tab, click Duplicate in the toolstrip. The scenario xbox1Copy appears in the Scenarios panel. Both scenarios decompose the image using the bior4.4 wavelet. In the new scenario, change the wavelet to the Haar (db1) wavelet and decompose. Form the reconstruction using all the coefficients except those corresponding to the diagonal (HH) details.


Export Results

You can either export the image decomposition to your MATLAB™ workspace or generate a script to reproduce the results.

To generate a script to recreate the xbox1Copy decomposition in your workspace, in the Analyzer tab, select Export ▼ > Generate MATLAB™ Script.


In the status bar, text appears stating that the script has been generated, and an untitled script opens in your editor with the executable code. You can save the script as is or modify it to apply the same decomposition settings to other images. To create the decomposition in your workspace, run the code. The script creates the workspace variable xbox1Copy_DWT. The variable is a structure with the fields:

  • transformedImage — This is the reconstructed image shown in the Original-Reconstructed Image pane.

  • decompositionCoefficients — This field corresponds to the wavelet decomposition vector the wavedec2 function outputs.

  • bookkeepingMatrix — This field corresponds to the bookkeeping matrix the wavedec2 function outputs.

If you instead chose to export the image decomposition, the same workspace variable xbox1Copy_DWT is created in your workspace.

Note: If you import an image from a file and export its decomposition, the workspace variable has a fourth structure field, originalImage, which contains the imported image.

% Variables for decomposition and reconstruction
waveletName = "db1";
decompositionLevel = 4;
% Detail gain columns are ordered by LH, HL, HH, rows are ordered by decomposition level
detailGain = [1 1 0;1 1 0;1 1 0;1 1 0];
lowpassGain = 1;

% Perform the decomposition using wavedec2
[C,S] = wavedec2(xbox,decompositionLevel,waveletName);

% Create decompositions by subbands and level
% using the detcoef2 and appcoef2 functions
decompositionTable = table(Size=[decompositionLevel,4], ...
    VariableTypes=["cell","cell","cell","cell"], ...

for levelIdx = 1:decompositionLevel
    % Create LH, HL, and HH subbands
    [decompositionTable.LH{levelIdx}, ...
        decompositionTable.HL{levelIdx}, ...
        decompositionTable.HH{levelIdx}] = detcoef2("all",C,S,levelIdx);

    % Create LL subband
    decompositionTable.LL{levelIdx} = appcoef2(C,S,waveletName,levelIdx);

% Create reconstructed image using waverec2
reconstructedImage = waverec2(C,S,waveletName, ...

% Create structure for reconstruction data
xbox1Copy_DWT = struct();
xbox1Copy_DWT.transformedImage = reconstructedImage;
xbox1Copy_DWT.decompositionCoefficients = C;
xbox1Copy_DWT.bookkeepingMatrix = S;

% To view coefficients with the "imshow" function, try scaling them with
% the "wcodemat" function. For example:
% >> imshow(uint8(wcodemat(decompositionTable.LH{decompositionLevel},255)));

Compare the original and reconstructed images.

cb = colorbar;
cb.Layout.Tile = "east";

Figure contains 2 axes objects. Axes object 1 with title Original contains an object of type image. Axes object 2 with title Reconstruction contains an object of type image.

Programmatic Use

expand all

waveletImageAnalyzer opens the Wavelet Image Analyzer app. Once the app initializes, import an image for analysis by clicking Import. The image can be in your workspace or file system.

waveletImageAnalyzer(img) opens the Wavelet Image Analyzer app and imports, decomposes, and displays the 2-D discrete wavelet transform (DWT) decomposition of img using the wavedec2 function with the bior4.4 wavelet and default settings.

img is a variable in the workspace. img can be:

  • An M-by-N real-valued matrix representing an indexed image or an M-by-N-by-3 real-valued array representing a truecolor image. For more information on truecolor images, see RGB (Truecolor) Images.

  • Of data type single, double, uint8, or uint16.


  • To decompose more than one image simultaneously, run multiple instances of the Wavelet Image Analyzer app.

Version History

Introduced in R2023a