2D Discrete Wavelet Transform. Parameters ---------- data : array_like 2D array with input data wavelet : Wavelet object or name string, or 2-tuple of wavelets Wavelet to use. This can also be a tuple containing a wavelet to apply along each axis in ``a
(data, wavelet, mode='symmetric', axes=(-2, -1))
| 20 | |
| 21 | |
| 22 | def dwt2(data, wavelet, mode='symmetric', axes=(-2, -1)): |
| 23 | """ |
| 24 | 2D Discrete Wavelet Transform. |
| 25 | |
| 26 | Parameters |
| 27 | ---------- |
| 28 | data : array_like |
| 29 | 2D array with input data |
| 30 | wavelet : Wavelet object or name string, or 2-tuple of wavelets |
| 31 | Wavelet to use. This can also be a tuple containing a wavelet to |
| 32 | apply along each axis in ``axes``. |
| 33 | mode : str or 2-tuple of strings, optional |
| 34 | Signal extension mode, see :ref:`Modes <ref-modes>`. This can |
| 35 | also be a tuple of modes specifying the mode to use on each axis in |
| 36 | ``axes``. |
| 37 | axes : 2-tuple of ints, optional |
| 38 | Axes over which to compute the DWT. Repeated elements mean the DWT will |
| 39 | be performed multiple times along these axes. |
| 40 | |
| 41 | Returns |
| 42 | ------- |
| 43 | (cA, (cH, cV, cD)) : tuple |
| 44 | Approximation, horizontal detail, vertical detail and diagonal |
| 45 | detail coefficients respectively. Horizontal refers to array axis 0 |
| 46 | (or ``axes[0]`` for user-specified ``axes``). |
| 47 | |
| 48 | Examples |
| 49 | -------- |
| 50 | >>> import numpy as np |
| 51 | >>> import pywt |
| 52 | >>> data = np.ones((4,4), dtype=np.float64) |
| 53 | >>> coeffs = pywt.dwt2(data, 'haar') |
| 54 | >>> cA, (cH, cV, cD) = coeffs |
| 55 | >>> cA |
| 56 | array([[ 2., 2.], |
| 57 | [ 2., 2.]]) |
| 58 | >>> cV |
| 59 | array([[ 0., 0.], |
| 60 | [ 0., 0.]]) |
| 61 | |
| 62 | """ |
| 63 | axes = tuple(axes) |
| 64 | data = np.asarray(data) |
| 65 | if len(axes) != 2: |
| 66 | raise ValueError("Expected 2 axes") |
| 67 | if data.ndim < len(np.unique(axes)): |
| 68 | raise ValueError("Input array has fewer dimensions than the specified " |
| 69 | "axes") |
| 70 | |
| 71 | coefs = dwtn(data, wavelet, mode, axes) |
| 72 | return coefs['aa'], (coefs['da'], coefs['ad'], coefs['dd']) |
| 73 | |
| 74 | |
| 75 | def idwt2(coeffs, wavelet, mode='symmetric', axes=(-2, -1)): |
no test coverage detected