本文整理汇总了Python中pywt.array_to_coeffs方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.array_to_coeffs方法的具体用法?Python pywt.array_to_coeffs怎么用?Python pywt.array_to_coeffs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywt
的用法示例。
在下文中一共展示了pywt.array_to_coeffs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wavedecn_coeff_reshape_even
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [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)
示例2: test_waverecn_coeff_reshape_odd
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [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)
示例3: recon
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [as 别名]
def recon(self,z1):
"""
Wavelet reconstruction: coefficients -> image
"""
coeffs = pywt.array_to_coeffs(z1, self.coeff_slices, \
output_format='wavedec2')
z0 = pywt.waverec2(coeffs, wavelet=self.wavelet, mode=self.mode)
return z0
示例4: _rmatvec
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [as 别名]
def _rmatvec(self, x):
x = np.reshape(x, self.dimsd)
x = pywt.array_to_coeffs(x, self.sl, output_format='wavedec2')
y = pywt.waverec2(x, wavelet=self.waveletadj, mode='periodization',
axes=self.dirs)
y = self.pad.rmatvec(y.ravel())
return y
示例5: _rmatvec
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [as 别名]
def _rmatvec(self, x):
if self.reshape:
x = np.reshape(x, self.dimsd)
x = pywt.array_to_coeffs(x, self.sl, output_format='wavedecn')
y = pywt.waverecn(x, wavelet=self.waveletadj, mode='periodization',
axes=(self.dir, ))
y = self.pad.rmatvec(y.ravel())
return y
示例6: inverse_wavelet_transform
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [as 别名]
def inverse_wavelet_transform(w_coeffs_rgb, coeff_slices, x_shape):
x_hat = np.zeros(x_shape)
for i in range(w_coeffs_rgb.shape[0]):
w_coeffs_list = pywt.array_to_coeffs(w_coeffs_rgb[i,:,:], coeff_slices)
x_hat[0,:,:,i] = pywt.waverecn(w_coeffs_list, wavelet='db4', mode='periodization')
return x_hat
示例7: test_wavedecn_coeff_reshape_axes_subset
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [as 别名]
def test_wavedecn_coeff_reshape_axes_subset():
# verify round trip is correct when only a subset of axes are transformed:
# wavedecn - >coeffs_to_array-> array_to_coeffs -> waverecn
# This is done for wavedec{1, 2, n}
rng = np.random.RandomState(1234)
mode = 'symmetric'
w = pywt.Wavelet('db2')
N = 16
ndim = 3
for axes in [(-1, ), (0, ), (1, ), (0, 1), (1, 2), (0, 2), None]:
x1 = rng.randn(*([N] * ndim))
coeffs = pywt.wavedecn(x1, w, mode=mode, axes=axes)
coeff_arr, coeff_slices = pywt.coeffs_to_array(coeffs, axes=axes)
if axes is not None:
# if axes is not None, it must be provided to coeffs_to_array
assert_raises(ValueError, pywt.coeffs_to_array, coeffs)
# mismatched axes size
assert_raises(ValueError, pywt.coeffs_to_array, coeffs,
axes=(0, 1, 2, 3))
assert_raises(ValueError, pywt.coeffs_to_array, coeffs,
axes=())
coeffs2 = pywt.array_to_coeffs(coeff_arr, coeff_slices)
x1r = pywt.waverecn(coeffs2, w, mode=mode, axes=axes)
assert_allclose(x1, x1r, rtol=1e-4, atol=1e-4)
示例8: test_array_to_coeffs_invalid_inputs
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import array_to_coeffs [as 别名]
def test_array_to_coeffs_invalid_inputs():
coeffs = pywt.wavedecn(np.ones(2), 'haar')
arr, arr_slices = pywt.coeffs_to_array(coeffs)
# empty list of array slices
assert_raises(ValueError, pywt.array_to_coeffs, arr, [])
# invalid format name
assert_raises(ValueError, pywt.array_to_coeffs, arr, arr_slices, 'foo')