本文整理汇总了Python中pywt.dwt_max_level方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.dwt_max_level方法的具体用法?Python pywt.dwt_max_level怎么用?Python pywt.dwt_max_level使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywt
的用法示例。
在下文中一共展示了pywt.dwt_max_level方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _wavelet_coefs
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def _wavelet_coefs(data, wavelet_name='db4'):
"""Compute Discrete Wavelet Transform coefficients.
Parameters
----------
data : ndarray, shape (n_channels, n_times)
wavelet_name : str (default: db4)
Wavelet name (to be used with ``pywt.Wavelet``). The full list of
Wavelet names are given by: ``[name for family in pywt.families() for
name in pywt.wavelist(family)]``.
Returns
-------
coefs : list of ndarray
Coefficients of a DWT (Discrete Wavelet Transform). ``coefs[0]`` is
the array of approximation coefficient and ``coefs[1:]`` is the list
of detail coefficients.
"""
wavelet = pywt.Wavelet(wavelet_name)
levdec = min(pywt.dwt_max_level(data.shape[-1], wavelet.dec_len), 6)
coefs = pywt.wavedec(data, wavelet=wavelet, level=levdec)
return coefs
示例2: compute_wavelet_feature_vector
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def compute_wavelet_feature_vector(image, wavelet='db6'):
image_np = np.array(image)
rgb = [image_np[:, :, i] for i in (0, 1, 2)]
if isinstance(wavelet, basestring):
wavelet = pywt.Wavelet(wavelet)
feature_vector = []
for c in rgb:
level = pywt.dwt_max_level(min(c.shape[0], c.shape[1]), wavelet.dec_len)
levels = pywt.wavedec2(c, wavelet, mode='sym', level=level)
for coeffs in levels:
if not isinstance(coeffs, tuple):
coeffs = (coeffs,)
for w in coeffs:
w_flat = w.flatten()
feature_vector += [float(np.mean(w_flat)), float(np.std(w_flat))]
return feature_vector
示例3: test_wavedecn_coeff_reshape_even
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def test_wavedecn_coeff_reshape_even():
# verify round trip is correct:
# wavedecn - >coeffs_to_array-> array_to_coeffs -> waverecn
# This is done for wavedec{1, 2, n}
rng = np.random.RandomState(1234)
params = {'wavedec': {'d': 1, 'dec': pywt.wavedec, 'rec': pywt.waverec},
'wavedec2': {'d': 2, 'dec': pywt.wavedec2, 'rec': pywt.waverec2},
'wavedecn': {'d': 3, 'dec': pywt.wavedecn, 'rec': pywt.waverecn}}
N = 28
for f in params:
x1 = rng.randn(*([N] * params[f]['d']))
for mode in pywt.Modes.modes:
for wave in wavelist:
w = pywt.Wavelet(wave)
maxlevel = pywt.dwt_max_level(np.min(x1.shape), w.dec_len)
if maxlevel == 0:
continue
coeffs = params[f]['dec'](x1, w, mode=mode)
coeff_arr, coeff_slices = pywt.coeffs_to_array(coeffs)
coeffs2 = pywt.array_to_coeffs(coeff_arr, coeff_slices,
output_format=f)
x1r = params[f]['rec'](coeffs2, w, mode=mode)
assert_allclose(x1, x1r, rtol=1e-4, atol=1e-4)
示例4: test_waverecn_coeff_reshape_odd
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def test_waverecn_coeff_reshape_odd():
# verify round trip is correct:
# wavedecn - >coeffs_to_array-> array_to_coeffs -> waverecn
rng = np.random.RandomState(1234)
x1 = rng.randn(35, 33)
for mode in pywt.Modes.modes:
for wave in ['haar', ]:
w = pywt.Wavelet(wave)
maxlevel = pywt.dwt_max_level(np.min(x1.shape), w.dec_len)
if maxlevel == 0:
continue
coeffs = pywt.wavedecn(x1, w, mode=mode)
coeff_arr, coeff_slices = pywt.coeffs_to_array(coeffs)
coeffs2 = pywt.array_to_coeffs(coeff_arr, coeff_slices)
x1r = pywt.waverecn(coeffs2, w, mode=mode)
# truncate reconstructed values to original shape
x1r = x1r[[slice(s) for s in x1.shape]]
assert_allclose(x1, x1r, rtol=1e-4, atol=1e-4)
示例5: test_wavedec
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def test_wavedec():
x = [3, 7, 1, 1, -2, 5, 4, 6]
db1 = pywt.Wavelet('db1')
cA3, cD3, cD2, cD1 = pywt.wavedec(x, db1)
assert_almost_equal(cA3, [8.83883476])
assert_almost_equal(cD3, [-0.35355339])
assert_allclose(cD2, [4., -3.5])
assert_allclose(cD1, [-2.82842712, 0, -4.94974747, -1.41421356])
assert_(pywt.dwt_max_level(len(x), db1) == 3)
示例6: test_compare_downcoef_coeffs
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def test_compare_downcoef_coeffs():
rstate = np.random.RandomState(1234)
r = rstate.randn(16)
# compare downcoef against wavedec outputs
for nlevels in [1, 2, 3]:
for wavelet in pywt.wavelist():
wavelet = pywt.DiscreteContinuousWavelet(wavelet)
if isinstance(wavelet, pywt.Wavelet):
max_level = pywt.dwt_max_level(r.size, wavelet.dec_len)
if nlevels <= max_level:
a = pywt.downcoef('a', r, wavelet, level=nlevels)
d = pywt.downcoef('d', r, wavelet, level=nlevels)
coeffs = pywt.wavedec(r, wavelet, level=nlevels)
assert_allclose(a, coeffs[0])
assert_allclose(d, coeffs[1])
示例7: test_dwt_max_level
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def test_dwt_max_level():
assert_(pywt.dwt_max_level(16, 2) == 4)
assert_(pywt.dwt_max_level(16, 8) == 1)
assert_(pywt.dwt_max_level(16, 9) == 1)
assert_(pywt.dwt_max_level(16, 10) == 0)
assert_(pywt.dwt_max_level(16, 18) == 0)
示例8: dt_max_level
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def dt_max_level(data, first_stage, wavelet, axis=-1):
"""
Returns the maximum decomposition level possible from the dual-tree complex wavelet transform.
Parameters
----------
data : ndarray
Input data. Can be of any dimension.
first_stage : str
Wavelet to use for the first stage. See :func:`skued.available_first_stage_filters` for a list of suitable arguments
wavelet : str
Wavelet to use in stages > 1. Must be appropriate for the dual-tree complex wavelet transform.
See :func:`skued.available_dt_filters` for possible values.
axis : int, optional
Axis over which to compute the transform. Default is -1
Returns
-------
max_level : int
Maximum decomposition level.
"""
real_wavelet, imag_wavelet = dualtree_wavelet(wavelet)
return dwt_max_level(
data_len=data.shape[axis],
filter_len=max([real_wavelet.dec_len, imag_wavelet.dec_len]),
)
示例9: fwt
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def fwt(input, wave_name='db4', axes=None, level=None, apply_zpad=True):
"""Forward wavelet transform.
Args:
input (array): Input array.
wave_name (str): Wavelet name.
axes (None or tuple of int): Axes to perform wavelet transform.
level (None or int): Number of wavelet levels.
apply_zpad (bool): If true, zero-pad for linear convolution.
"""
device = backend.get_device(input)
xp = device.xp
if axes is None:
axes = tuple([k for k in range(len(input.shape))
if input.shape[k] > 1])
if (type(axes) == int):
axes = (axes,)
wavdct = pywt.Wavelet(wave_name)
dec_lo = xp.array(wavdct.dec_lo)
dec_hi = xp.array(wavdct.dec_hi)
if level is None:
level = pywt.dwt_max_level(
xp.min(xp.array([input.shape[ax] for ax in axes])),
dec_lo.size)
if level <= 0:
return input
assert level > 0
y = apply_dec_along_axis(input, axes, dec_lo, dec_hi, level, apply_zpad)
approx_idx = tuple([slice(0, y.shape[k]//2)
if k in axes else slice(0, None)
for k in range(len(input.shape))])
y[approx_idx] = fwt(y[approx_idx], wave_name=wave_name,
axes=axes, level=level-1, apply_zpad=False)
return y
示例10: iwt
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt_max_level [as 别名]
def iwt(input, oshape, wave_name='db4', axes=None, level=None, inplace=False):
"""Inverse wavelet transform.
Args:
input (array): Input array.
oshape (tuple): Output shape.
wave_name (str): Wavelet name.
axes (None or tuple of int): Axes to perform wavelet transform.
level (None or int): Number of wavelet levels.
inplace (bool): Modify input array in place.
"""
device = backend.get_device(input)
xp = device.xp
if axes is None:
axes = tuple([k for k in range(len(input.shape))
if input.shape[k] > 1])
if (type(axes) == int):
axes = (axes,)
wavdct = pywt.Wavelet(wave_name)
rec_lo = xp.array(wavdct.rec_lo)
rec_hi = xp.array(wavdct.rec_hi)
if level is None:
level = pywt.dwt_max_level(
xp.min(xp.array([input.shape[ax] for ax in axes])),
rec_lo.size)
if level <= 0:
return input
assert level > 0
for ax in axes:
assert input.shape[ax] % 2 == 0
x = input if inplace else input.astype(xp.complex64).copy()
approx_idx = tuple([slice(0, input.shape[k]//2)
if k in axes else slice(0, None)
for k in range(len(input.shape))])
x[approx_idx] = iwt(x[approx_idx], input[approx_idx].shape,
wave_name=wave_name, axes=axes, level=level-1,
inplace=True)
y = apply_rec_along_axis(x, axes, rec_lo, rec_hi)
crop_idx = tuple([slice(0, oshape[k])
if k in axes else slice(0, None)
for k in range(len(input.shape))])
return y[crop_idx]