nD Forward and Inverse Discrete Wavelet Transform¶
|
Multilevel 1D and 2D Discrete Wavelet Transform and Inverse Discrete Wavelet Transform. |
Single level - dwtn
¶
- pywt.dwtn(data, wavelet, mode='symmetric', axes=None)¶
Single-level n-dimensional Discrete Wavelet Transform.
- Parameters
- dataarray_like
n-dimensional array with input data.
- waveletWavelet object or name string, or tuple of wavelets
Wavelet to use. This can also be a tuple containing a wavelet to apply along each axis in
axes
.- modestr or tuple of string, optional
Signal extension mode used in the decomposition, see Modes. This can also be a tuple of modes specifying the mode to use on each axis in
axes
.- axessequence 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 themode
parameter.pywt.wavedecn
should be used for multilevel decomposition.
- Returns
- coeffsdict
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 specifiedaxes
.
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 orNone
items will be treated as zeros.- waveletWavelet object or name string, or tuple of wavelets
Wavelet to use. This can also be a tuple containing a wavelet to apply along each axis in
axes
.- modestr or list of string, optional
Signal extension mode used in the decomposition, see Modes. This can also be a tuple of modes specifying the mode to use on each axis in
axes
.- axessequence 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
- datandarray
nD input data
- waveletWavelet object or name string, or tuple of wavelets
Wavelet to use. This can also be a tuple containing a wavelet to apply along each axis in
axes
.- modestr or tuple of str, optional
Signal extension mode, see Modes. This can also be a tuple containing a mode to apply along each axis in
axes
.- levelint, optional
Decomposition level (must be >= 0). If level is None (default) then it will be calculated using the
dwt_max_level
function.- axessequence 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 leveln
. Eachdetails_level_i
element is a dictionary containing detail coefficients at leveli
of the decomposition. As a concrete example, a 3D decomposition would have the following set of keys in eachdetails_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.
- coeffsarray_like
Coefficients list [cAn, {details_level_n}, … {details_level_1}]
- waveletWavelet object or name string, or tuple of wavelets
Wavelet to use. This can also be a tuple containing a wavelet to apply along each axis in
axes
.- modestr or tuple of str, optional
Signal extension mode, see Modes. This can also be a tuple containing a mode to apply along each axis in
axes
.- axessequence of ints, optional
Axes over which to compute the IDWT. Axes may not be repeated.
- Returns
- nD array of reconstructed data.
Notes
It may sometimes be desired to run
waverecn
with some sets of coefficients omitted. This can best be done by setting the corresponding arrays to zero arrays of matching shape and dtype. Explicitly removing list or dictionary entries or setting them to None is not supported.Specifically, to ignore all detail coefficients at level 2, one could do:
coeffs[-2] = {k: np.zeros_like(v) for k, v in coeffs[-2].items()}
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 fully separable decomposition - fswavedecn
¶
- pywt.fswavedecn(data, wavelet, mode='symmetric', levels=None, axes=None)¶
Fully Separable Wavelet Decomposition.
This is a variant of the multilevel discrete wavelet transform where all levels of decomposition are performed along a single axis prior to moving onto the next axis. Unlike in
wavedecn
, the number of levels of decomposition are not required to be the same along each axis which can be a benefit for anisotropic data.- Parameters
- data: array_like
Input data
- waveletWavelet object or name string, or tuple of wavelets
Wavelet to use. This can also be a tuple containing a wavelet to apply along each axis in
axes
.- modestr or tuple of str, optional
Signal extension mode, see Modes. This can also be a tuple containing a mode to apply along each axis in
axes
.- levelsint or sequence of ints, optional
Decomposition levels along each axis (must be >= 0). If an integer is provided, the same number of levels are used for all axes. If
levels
is None (default),dwt_max_level
will be used to compute the maximum number of levels possible for each axis.- axessequence of ints, optional
Axes over which to compute the transform. Axes may not be repeated. The default is to transform along all axes.
- Returns
- fswavedecn_resultFswavedecnResult object
Contains the wavelet coefficients, slice objects to allow obtaining the coefficients per detail or approximation level, and more. See
FswavedecnResult
for details.
See also
fswaverecn
inverse of fswavedecn
Notes
This transformation has been variously referred to as the (fully) separable wavelet transform (e.g. refs [1], [3]), the tensor-product wavelet ([2]) or the hyperbolic wavelet transform ([4]). It is well suited to data with anisotropic smoothness.
In [2] it was demonstrated that fully separable transform performs at least as well as the DWT for image compression. Computation time is a factor 2 larger than that for the DWT.
References
- 1
PH Westerink. Subband Coding of Images. Ph.D. dissertation, Dept. Elect. Eng., Inf. Theory Group, Delft Univ. Technol., Delft, The Netherlands, 1989. (see Section 2.3) http://resolver.tudelft.nl/uuid:a4d195c3-1f89-4d66-913d-db9af0969509
- 2(1,2)
CP Rosiene and TQ Nguyen. Tensor-product wavelet vs. Mallat decomposition: A comparative analysis, in Proc. IEEE Int. Symp. Circuits and Systems, Orlando, FL, Jun. 1999, pp. 431-434.
- 3
V Velisavljevic, B Beferull-Lozano, M Vetterli and PL Dragotti. Directionlets: Anisotropic Multidirectional Representation With Separable Filtering. IEEE Transactions on Image Processing, Vol. 15, No. 7, July 2006.
- 4
RA DeVore, SV Konyagin and VN Temlyakov. “Hyperbolic wavelet approximation,” Constr. Approx. 14 (1998), 1-26.
Examples
>>> from pywt import fswavedecn >>> fs_result = fswavedecn(np.ones((32, 32)), 'sym2', levels=(1, 3)) >>> print(fs_result.detail_keys()) [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3)] >>> approx_coeffs = fs_result.approx >>> detail_1_2 = fs_result[(1, 2)]
Multilevel fully separable reconstruction - fswaverecn
¶
- pywt.fswaverecn(fswavedecn_result)¶
Fully Separable Inverse Wavelet Reconstruction.
- Parameters
- fswavedecn_resultFswavedecnResult object
FswavedecnResult object from
fswavedecn
.
- Returns
- reconstructedndarray
Array of reconstructed data.
See also
fswavedecn
inverse of fswaverecn
Notes
This transformation has been variously referred to as the (fully) separable wavelet transform (e.g. refs [1], [3]), the tensor-product wavelet ([2]) or the hyperbolic wavelet transform ([4]). It is well suited to data with anisotropic smoothness.
In [2] it was demonstrated that the fully separable transform performs at least as well as the DWT for image compression. Computation time is a factor 2 larger than that for the DWT.
References
- 1
PH Westerink. Subband Coding of Images. Ph.D. dissertation, Dept. Elect. Eng., Inf. Theory Group, Delft Univ. Technol., Delft, The Netherlands, 1989. (see Section 2.3) http://resolver.tudelft.nl/uuid:a4d195c3-1f89-4d66-913d-db9af0969509
- 2(1,2)
CP Rosiene and TQ Nguyen. Tensor-product wavelet vs. Mallat decomposition: A comparative analysis, in Proc. IEEE Int. Symp. Circuits and Systems, Orlando, FL, Jun. 1999, pp. 431-434.
- 3
V Velisavljevic, B Beferull-Lozano, M Vetterli and PL Dragotti. Directionlets: Anisotropic Multidirectional Representation With Separable Filtering. IEEE Transactions on Image Processing, Vol. 15, No. 7, July 2006.
- 4
RA DeVore, SV Konyagin and VN Temlyakov. “Hyperbolic wavelet approximation,” Constr. Approx. 14 (1998), 1-26.
Multilevel fully separable reconstruction coeffs - FswavedecnResult
¶
- class pywt.FswavedecnResult(coeffs, coeff_slices, wavelets, mode_enums, axes)¶
Object representing fully separable wavelet transform coefficients.
- Parameters
- coeffsndarray
The coefficient array.
- coeff_sliceslist
List of slices corresponding to each detail or approximation coefficient array.
- waveletslist of pywt.DiscreteWavelet objects
The wavelets used. Will be a list with length equal to
len(axes)
.- mode_enumslist of int
The border modes used. Will be a list with length equal to
len(axes)
.- axestuple of int
The set of axes over which the transform was performed.
- Attributes
approx
ndarray: The approximation coefficients.
axes
List of str: The axes the transform was performed along.
coeff_slices
List: List of coefficient slices.
coeffs
ndarray: All coefficients stacked into a single array.
levels
List of int: Levels of decomposition along each transformed axis.
modes
List of str: The border mode used along each transformed axis.
ndim
int: Number of data dimensions.
ndim_transform
int: Number of axes transformed.
wavelet_names
List of pywt.DiscreteWavelet: wavelet for each transformed axis.
wavelets
List of pywt.DiscreteWavelet: wavelet for each transformed axis.
Methods
detail_keys
()Return a list of all detail coefficient keys.