ucurv.meyerwavelet
Functions
|
Generate forward and inverse 1D Meyer wavelet filters of length N. |
|
Perform a 1-D Meyer wavelet forward transform along a specified axis. |
|
N-dimensional forward Meyer wavelet transform. |
|
Inverse 1-D Meyer wavelet transform along a chosen axis. |
|
Inverse N-dimensional Meyer wavelet transform. |
- ucurv.meyerwavelet.meyer_wavelet(N, engine: str = 'auto')[source]
Generate forward and inverse 1D Meyer wavelet filters of length N.
- Parameters:
N (int) – Number of samples (length of the wavelet filters).
- Returns:
f1 (ndarray) – The forward Meyer wavelet filter, computed as the square root of the FFT-shifted Meyer window on a grid of length N.
f2 (ndarray) – The inverse Meyer wavelet filter, computed as the square root of the unshifted Meyer window on the same grid.
Notes
This function constructs a spatial grid: x = linspace(0, 2π, N, endpoint=False) - π/2, and parameters: prm = π * [-1/3, 1/3, 2/3, 4/3]. It then calls fun_meyer(x, prm) to generate the Meyer window, applies FFT-shift for the forward filter, and takes the square roots.
- ucurv.meyerwavelet.meyerfwd1d(img, dim, engine: str = 'auto')[source]
Perform a 1-D Meyer wavelet forward transform along a specified axis.
This applies Meyer filters in the frequency domain, then splits and downsamples into low and high-frequency sub-bands.
- Parameters:
img (ndarray) – Incput array of arbitrary shape. The transform is applied along one axis; all other dimensions are preserved.
dim (int) – Axis (0 ≤
dim<img.ndim) along which to compute the 1-D Meyer transform.
- Returns:
h1 (ndarray) – The low-frequency sub-band. Same shape as img except along dim, where the length is
N/2(even samples).h2 (ndarray) – The high frequency sub band (odd samples); shape identical to h1.
Notes
Internally this function:
Swaps axis dim with the last axis.
Computes length
NMeyer filtersf1andf2.FFTs the incput along that axis.
Multiplies by
f1/f2and IFFTs back.Takes the real part and downsamples by 2:
h1 = [..., ::2](even),h2 = [..., 1::2](odd).Swaps axes back to restore the original layout.
Examples
>>> import numpy as ncp >>> x = ncp.random.randn(100, 200) >>> low, high = meyerfwd1d(x, dim=1) >>> low.shape, high.shape ((100, 100), (100, 100))
- ucurv.meyerwavelet.meyerfwdmd(img, engine: str = 'auto')[source]
N-dimensional forward Meyer wavelet transform.
The routine applies the 1-D forward Meyer filters successively along each axis of the incput array, splitting the data into low- and high-frequency sub-bands at every step.
- Parameters:
img (ndarray) – Incput array of arbitrary dimensionality. The transform is applied along axis 0, then axis 1, and so on up to
img.ndim - 1.- Returns:
cband – List of length
2**Ncontaining the sub-band arrays, whereN = img.ndim. Each decomposition level doubles the number of bands by splitting every current band into its low- and high-frequency components.- Return type:
list of ndarray
Notes
Axis 0 - the first call to
meyerfwd1d()splits img into[h1, h2].Axis i ( i ≥ 1 ) - every existing band is split again along axis i, so after processing axis i the total number of bands is
2**(i + 1).
Examples
>>> import numpy as ncp >>> x = ncp.random.randn(8, 8, 8) # 3-D array (N = 3) >>> subbands = meyerfwdmd(x) >>> len(subbands) 8
- ucurv.meyerwavelet.meyerinv1d(h1, h2, dim, engine: str = 'auto')[source]
Inverse 1-D Meyer wavelet transform along a chosen axis.
The routine reconstructs the original signal by interleaving the low- and high-frequency sub-bands, applying the Meyer synthesis filters in the frequency domain, and summing the results.
- Parameters:
h1 (ndarray) – Low-frequency sub-band. Same shape as the original incput except along dim, where its length is
N/2(even samples).h2 (ndarray) – High-frequency sub-band; shape identical to h1 (odd samples).
dim (int) – Axis along which the forward transform was taken (
0 <= dim < h1.ndim).
- Returns:
imrecon – Reconstructed array with the same shape and
dtypeas the original incput tomeyerfwd1d().- Return type:
ndarray
Notes
Internally the function proceeds as follows:
Swap axis dim with the last axis.
Build two length-
Narraysg1andg2by placingh1in the even indices ([..., ::2]) andh2in the odd indices ([..., 1::2]).Compute Meyer synthesis filters
f1andf2of lengthN.FFT
g1andg2along the last axis, multiply byf1/f2, and sum in the frequency domain.Apply the inverse FFT, take the real part, and scale by 2.
Swap axes back to restore the original layout.
Examples
>>> import numpy as ncp >>> x = ncp.random.randn(64, 128) >>> low, high = meyerfwd1d(x, dim=1) >>> x_rec = meyerinv1d(low, high, dim=1) >>> ncp.allclose(x, x_rec, atol=1e-6) True
- ucurv.meyerwavelet.meyerinvmd(band, engine: str = 'auto')[source]
Inverse N-dimensional Meyer wavelet transform.
Reconstruct the original array from the
2**Nsub-bands returned bymeyerfwdmd()by successively merging low- and high-frequency components along each axis.- Parameters:
band (list[numpy.ndarray]) – Sequence of
2**Nsub-band arrays produced bymeyerfwdmd(). The order must match exactly the order returned by that function for the same incput dimensions.- Returns:
img_recon – Array with the same shape and
dtypeas the data that was passed tomeyerfwdmd().- Return type:
numpy.ndarray
Notes
The reconstruction proceeds in reverse axis order:
Start with axis
N - 1; pair each low/high band and merge them withmeyerinv1d()along that axis, halving the number of bands.Repeat the pairing-and-merge step for the next smaller axis.
Continue until only one band remains—the fully reconstructed signal.
Examples
>>> import numpy as ncp >>> x = ncp.random.randn(8, 8, 8) >>> subbands = meyerfwdmd(x) >>> x_rec = meyerinvmd(subbands) >>> ncp.allclose(x, x_rec, atol=1e-6) True