# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# wavedec2

Multilevel 2-D wavelet decomposition

## Syntax

```[C,S] = wavedec2(X,N,'wname') [C,S] = wavedec2(X,N,Lo_D,Hi_D) ```

## Description

`wavedec2` is a two-dimensional wavelet analysis function.

`[C,S] = wavedec2(X,N,'wname')` returns the wavelet decomposition of the matrix `X` at level `N`, using the wavelet named in character vector `'wname'` (see `wfilters` for more information).

Outputs are the decomposition vector `C` and the corresponding bookkeeping matrix `S`.

`N` must be a strictly positive integer (see `wmaxlev` for more information).

Instead of giving the wavelet name, you can give the filters.

For `[C,S] = wavedec2(X,N,Lo_D,Hi_D)`, `Lo_D` is the decomposition low-pass filter and `Hi_D` is the decomposition high-pass filter.

Vector `C` is organized as a vector with A(N), H(N), V(N), D(N), H(N-1), V(N-1), D(N-1), ..., H(1), V(1), D(1), where `A`, `H`, `V`, and `D` are each a row vector. Each vector is the vector column-wise storage of a matrix.

• `A` contains the approximation coefficients

• `H` contains the horizontal detail coefficients

• `V` contains the vertical detail coefficients

• `D` contains the diagonal detail coefficients

Matrix `S` is such that

• `S(1,:)` = size of approximation coefficients(`N`).

• `S(i,:)` = size of detail coefficients(`N-i+2`) for `i` = 2, ...`N+1` and ```S(N+2,:) = size(X)```.

## Examples

### Decomposition Structure

This example shows the structure of `wavedec2` output matrices.

Load original image from the `woman.mat` file, which contains variables named `X` and `map`.

`load woman;`

Get current discrete wavelet transform extension mode.

`origMode = dwtmode('status','nodisplay');`

Change to periodic boundary handling.

`dwtmode('per');`
``` !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! WARNING: Change DWT Extension Mode ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ***************************************** ** DWT Extension Mode: Periodization ** ***************************************** ```

Perform decomposition at level 2 of `X` using db1.

`[c,s] = wavedec2(X,2,'db1');`

Get the decomposition structure organization.

`sizex = size(X)`
```sizex = 256 256 ```
`sizec = size(c)`
```sizec = 1 65536 ```

Reset discrete wavelet transform extension mode to its original mode.

`dwtmode(origMode);`
``` !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! WARNING: Change DWT Extension Mode ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ******************************************************* ** DWT Extension Mode: Symmetrization (half-point) ** ******************************************************* ```

### Extract and Display Image Decomposition Level

Extract and display images of wavelet decomposition level details. The resulting images are similar to the visualizations in the At level 2, with haar --> woman indexed image example in the Wavelet 2-D interactive tool. Use `waveletAnalyzer` to launch this tool.

```load woman; [c,s]=wavedec2(X,2,'haar');```
```[H1,V1,D1] = detcoef2('all',c,s,1); A1 = appcoef2(c,s,'haar',1); V1img = wcodemat(V1,255,'mat',1); H1img = wcodemat(H1,255,'mat',1); D1img = wcodemat(D1,255,'mat',1); A1img = wcodemat(A1,255,'mat',1);```
```[H2,V2,D2] = detcoef2('all',c,s,2); A2 = appcoef2(c,s,'haar',2); V2img = wcodemat(V2,255,'mat',1); H2img = wcodemat(H2,255,'mat',1); D2img = wcodemat(D2,255,'mat',1); A2img = wcodemat(A2,255,'mat',1);```
```subplot(2,2,1); imagesc(A1img); colormap pink(255); title('Approximation Coef. of Level 1'); subplot(2,2,2); imagesc(H1img); title('Horizontal detail Coef. of Level 1'); subplot(2,2,3); imagesc(V1img); title('Vertical detail Coef. of Level 1'); subplot(2,2,4); imagesc(D1img); title('Diagonal detail Coef. of Level 1');```

```figure; subplot(2,2,1); imagesc(A2img); colormap pink(255); title('Approximation Coef. of Level 2'); subplot(2,2,2) imagesc(H2img); title('Horizontal detail Coef. of Level 2'); subplot(2,2,3) imagesc(V2img); title('Vertical detail Coef. of Level 2'); subplot(2,2,4) imagesc(D2img); title('Diagonal detail Coef. of Level 2');```

## Tips

When X represents an indexed image, X, as well as the output arrays cA,cH,cV, and cD are `m`-by-`n` matrices. When X represents a truecolor image, it is an `m`-by-`n`-by-3 array, where each `m`-by-`n` matrix represents a red, green, or blue color plane concatenated along the third dimension. The size of vector C and the size of matrix `S` depend on the type of analyzed image.

For a truecolor image, the decomposition vector `C` and the corresponding bookkeeping matrix `S` can be represented as follows.

For more information on image formats, see the `image` and `imfinfo` reference pages.

## Algorithms

For images, an algorithm similar to the one-dimensional case is possible for two-dimensional wavelets and scaling functions obtained from one-dimensional ones by tensor product.

This kind of two-dimensional DWT leads to a decomposition of approximation coefficients at level j in four components: the approximation at level j+1, and the details in three orientations (horizontal, vertical, and diagonal).

The following chart describes the basic decomposition step for images:

So, for J=2, the two-dimensional wavelet tree has the form

## References

Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)