nD Forward and Inverse Discrete Wavelet Transform

Single level - dwtn

pywt.dwtn(data, wavelet, mode='symmetric', axes=None)

Single-level n-dimensional Discrete Wavelet Transform.

Parameters:

data : array_like

n-dimensional array with input data.

wavelet : Wavelet object or name string

Wavelet to use.

mode : str, optional

Signal extension mode, see Modes. Default is ‘symmetric’.

axes : sequence of ints, optional

Axes over which to compute the DWT. Repeated elements mean the DWT will be performed multiple times along these axes. A value of None (the default) selects all axes.

Axes may be repeated, but information about the original size may be lost if it is not divisible by 2 ** nrepeats. The reconstruction will be larger, with additional values derived according to the mode parameter. pywt.wavedecn should be used for multilevel decomposition.

Returns:

coeffs : dict

Results are arranged in a dictionary, where key specifies the transform type on each dimension and value is a n-dimensional coefficients array.

For example, for a 2D case the result will look something like this:

{'aa': <coeffs>  # A(LL) - approx. on 1st dim, approx. on 2nd dim
 'ad': <coeffs>  # V(LH) - approx. on 1st dim, det. on 2nd dim
 'da': <coeffs>  # H(HL) - det. on 1st dim, approx. on 2nd dim
 'dd': <coeffs>  # D(HH) - det. on 1st dim, det. on 2nd dim
}

For user-specified axes, the order of the characters in the dictionary keys map to the specified axes.

Single level - idwtn

pywt.idwtn(coeffs, wavelet, mode='symmetric', axes=None)

Single-level n-dimensional Inverse Discrete Wavelet Transform.

Parameters:

coeffs: dict

Dictionary as in output of dwtn. Missing or None items will be treated as zeroes.

wavelet : Wavelet object or name string

Wavelet to use

mode : str, optional

Signal extension mode used in the decomposition, see Modes (default: ‘symmetric’).

axes : sequence of ints, optional

Axes over which to compute the IDWT. Repeated elements mean the IDWT will be performed multiple times along these axes. A value of None (the default) selects all axes.

For the most accurate reconstruction, the axes should be provided in the same order as they were provided to dwtn.

Returns:

data: ndarray

Original signal reconstructed from input data.

Multilevel decomposition - wavedecn

pywt.wavedecn(data, wavelet, mode='symmetric', level=None, axes=None)

Multilevel nD Discrete Wavelet Transform.

Parameters:

data : ndarray

nD input data

wavelet : Wavelet object or name string

Wavelet to use

mode : str, optional

Signal extension mode, see Modes (default: ‘symmetric’)

level : int, optional

Decomposition level (must be >= 0). If level is None (default) then it will be calculated using the dwt_max_level function.

axes : sequence of ints, optional

Axes over which to compute the DWT. Axes may not be repeated. The default is None, which means transform all axes (axes = range(data.ndim)).

Returns:

[cAn, {details_level_n}, ... {details_level_1}] : list

Coefficients list. Coefficients are listed in descending order of decomposition level. cAn are the approximation coefficients at level n. Each details_level_i element is a dictionary containing detail coefficients at level i of the decomposition. As a concrete example, a 3D decomposition would have the following set of keys in each details_level_i dictionary:

{'aad', 'ada', 'daa', 'add', 'dad', 'dda', 'ddd'}

where the order of the characters in each key map to the specified axes.

Examples

>>> import numpy as np
>>> from pywt import wavedecn, waverecn
>>> coeffs = wavedecn(np.ones((4, 4, 4)), 'db1')
>>> # Levels:
>>> len(coeffs)-1
2
>>> waverecn(coeffs, 'db1')  
array([[[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]]])

Multilevel reconstruction - waverecn

pywt.waverecn(coeffs, wavelet, mode='symmetric', axes=None)

Multilevel nD Inverse Discrete Wavelet Transform.

coeffs : array_like
Coefficients list [cAn, {details_level_n}, ... {details_level_1}]
wavelet : Wavelet object or name string
Wavelet to use
mode : str, optional
Signal extension mode, see Modes (default: ‘symmetric’)
axes : sequence of ints, optional
Axes over which to compute the IDWT. Axes may not be repeated.
Returns:nD array of reconstructed data.

Examples

>>> import numpy as np
>>> from pywt import wavedecn, waverecn
>>> coeffs = wavedecn(np.ones((4, 4, 4)), 'db1')
>>> # Levels:
>>> len(coeffs)-1
2
>>> waverecn(coeffs, 'db1')  
array([[[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],
       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]]])