PyWavelets documentation has moved to pywavelets.readthedocs.io. You will be automatically redirected there in 10 seconds.
2D Forward and Inverse Discrete Wavelet Transform¶
Single level dwt2
¶
-
pywt.
dwt2
(data, wavelet, mode='symmetric', axes=(-2, -1))¶ 2D Discrete Wavelet Transform.
Parameters: data : ndarray
2D array with input data
wavelet : Wavelet object or name string
Wavelet to use
mode : str, optional
Signal extension mode, see Modes (default: ‘symmetric’)
axes : 2-tuple of ints, optional
Axes over which to compute the DWT. Repeated elements mean the DWT will be performed multiple times along these axes.
Returns: (cA, (cH, cV, cD)) : tuple
Approximation, horizontal detail, vertical detail and diagonal detail coefficients respectively. Horizontal refers to array axis 0.
Examples
>>> import numpy as np >>> import pywt >>> data = np.ones((4,4), dtype=np.float64) >>> coeffs = pywt.dwt2(data, 'haar') >>> cA, (cH, cV, cD) = coeffs >>> cA array([[ 2., 2.], [ 2., 2.]]) >>> cV array([[ 0., 0.], [ 0., 0.]])
The relation to the other common data layout where all the approximation and details coefficients are stored in one big 2D array is as follows:
------------------- | | | | cA(LL) | cH(LH) | | | | (cA, (cH, cV, cD)) <---> ------------------- | | | | cV(HL) | cD(HH) | | | | -------------------
PyWavelets does not follow this pattern because of pure practical reasons of simple access to particular type of the output coefficients.
Single level idwt2
¶
-
pywt.
idwt2
(coeffs, wavelet, mode='symmetric', axes=(-2, -1))¶ 2-D Inverse Discrete Wavelet Transform.
Reconstructs data from coefficient arrays.
Parameters: coeffs : tuple
(cA, (cH, cV, cD)) A tuple with approximation coefficients and three details coefficients 2D arrays like from dwt2()
wavelet : Wavelet object or name string
Wavelet to use
mode : str, optional
Signal extension mode, see Modes (default: ‘symmetric’)
axes : 2-tuple of ints, optional
Axes over which to compute the IDWT. Repeated elements mean the IDWT will be performed multiple times along these axes.
Examples
>>> import numpy as np >>> import pywt >>> data = np.array([[1,2], [3,4]], dtype=np.float64) >>> coeffs = pywt.dwt2(data, 'haar') >>> pywt.idwt2(coeffs, 'haar') array([[ 1., 2.], [ 3., 4.]])
2D multilevel decomposition using wavedec2
¶
-
pywt.
wavedec2
(data, wavelet, mode='symmetric', level=None)¶ Multilevel 2D Discrete Wavelet Transform.
Parameters: data : ndarray
2D 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.Returns: [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)] : list
Coefficients list
Examples
>>> import pywt >>> import numpy as np >>> coeffs = pywt.wavedec2(np.ones((4,4)), 'db1') >>> # Levels: >>> len(coeffs)-1 2 >>> pywt.waverec2(coeffs, 'db1') array([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.]])
2D multilevel reconstruction using waverec2
¶
-
pywt.
waverec2
(coeffs, wavelet, mode='symmetric')¶ Multilevel 2D Inverse Discrete Wavelet Transform.
- coeffs : list or tuple
- Coefficients list [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)]
- wavelet : Wavelet object or name string
- Wavelet to use
- mode : str, optional
- Signal extension mode, see Modes (default: ‘symmetric’)
Returns: 2D array of reconstructed data. Examples
>>> import pywt >>> import numpy as np >>> coeffs = pywt.wavedec2(np.ones((4,4)), 'db1') >>> # Levels: >>> len(coeffs)-1 2 >>> pywt.waverec2(coeffs, 'db1') array([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.]])