本文整理汇总了Python中pywt.waverec2方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.waverec2方法的具体用法?Python pywt.waverec2怎么用?Python pywt.waverec2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywt
的用法示例。
在下文中一共展示了pywt.waverec2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_basis
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def generate_basis():
"""generate the basis"""
x = np.zeros((64, 64))
coefs = pywt.wavedec2(x, 'db1')
n_levels = len(coefs)
basis = []
for i in range(n_levels):
coefs[i] = list(coefs[i])
n_filters = len(coefs[i])
for j in range(n_filters):
for m in range(coefs[i][j].shape[0]):
try:
for n in range(coefs[i][j].shape[1]):
coefs[i][j][m][n] = 1
temp_basis = pywt.waverec2(coefs, 'db1')
basis.append(temp_basis)
coefs[i][j][m][n] = 0
except IndexError:
coefs[i][j][m] = 1
temp_basis = pywt.waverec2(coefs, 'db1')
basis.append(temp_basis)
coefs[i][j][m] = 0
basis = np.array(basis)
return basis
示例2: test_wavedecn_coeff_reshape_even
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [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)
示例3: fusion
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def fusion(self):
self._load_images()
coeffss = []
for image in self._images:
coeffss.append(pywt.wavedec2(image, 'db1', level=self._zt))
# low pass
if self._mp == 0:
cAF = coeffss[0][0]
for coeffs in coeffss[1:]:
cAF += coeffs[0]
cAF = cAF/len(coeffs)
# high pass
if self._ap == 2:
hipassF = coeffss[0][1:]
for coeffs in coeffss[1:]: # every image
for idxLevel, HVDs in enumerate(coeffs[1:]): # every level
for idxDirec, HVD in enumerate(HVDs):
maxMap = hipassF[idxLevel][idxDirec] < HVD
hipassF[idxLevel][idxDirec][maxMap] = HVD[maxMap]
coeffsFusion = [cAF,] + hipassF
self._fusionImage = pywt.waverec2(coeffsFusion, 'db1')
return self._fusionImage
示例4: hfilter
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def hfilter(diff_image, var_image, threshold=1, ndamp=10):
"""
This code was inspired from: https://github.com/spacetelescope/sprint_notebooks/blob/master/lucy_damped_haar.ipynb
I believe it was initially written by Justin Ely: https://github.com/justincely
It was buggy and not working properly with every image sizes.
I have thus exchanged it by using pyWavelet (pywt) and a custom function htrans
to calculate the matrix for the var_image.
"""
him, coeff_slices = pywt.coeffs_to_array(pywt.wavedec2(diff_image.astype(np.float), 'haar'), padding=0)
dvarim = htrans(var_image.astype(np.float))
sqhim = ((him/threshold)**2)/dvarim
index = np.where(sqhim < 1)
if len(index[0]) == 0:
return diff_image
# Eq. 8 of White is derived leading to N*x^(N-1)-(N-1)*x^N :DOI: 10.1117/12.176819
sqhim = sqhim[index] * (ndamp * sqhim[index]**(ndamp-1) - (ndamp-1)*sqhim[index]**ndamp)
him[index] = sign(threshold*np.sqrt(dvarim[index] * sqhim), him[index])
return pywt.waverec2(pywt.array_to_coeffs(him, coeff_slices, output_format='wavedec2'), 'haar')[:diff_image.shape[0],:diff_image.shape[1]]
示例5: generate_basis
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def generate_basis():
"""generate the basis"""
x = np.zeros((56, 56))
coefs = pywt.wavedec2(x, 'db1')
n_levels = len(coefs)
basis = []
for i in range(n_levels):
coefs[i] = list(coefs[i])
n_filters = len(coefs[i])
for j in range(n_filters):
for m in range(coefs[i][j].shape[0]):
try:
for n in range(coefs[i][j].shape[1]):
coefs[i][j][m][n] = 1
temp_basis = pywt.waverec2(coefs, 'db1')
basis.append(temp_basis)
coefs[i][j][m][n] = 0
except IndexError:
coefs[i][j][m] = 1
temp_basis = pywt.waverec2(coefs, 'db1')
basis.append(temp_basis)
coefs[i][j][m] = 0
basis = np.array(basis)
return basis
示例6: test_multilevel_dtypes_2d
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_multilevel_dtypes_2d():
wavelet = pywt.Wavelet('haar')
for dt_in, dt_out in zip(dtypes_in, dtypes_out):
# wavedec2, waverec2
x = np.ones((8, 8), dtype=dt_in)
errmsg = "wrong dtype returned for {0} input".format(dt_in)
cA, coeffsD2, coeffsD1 = pywt.wavedec2(x, wavelet, level=2)
assert_(cA.dtype == dt_out, "wavedec2: " + errmsg)
for c in coeffsD1:
assert_(c.dtype == dt_out, "wavedec2: " + errmsg)
for c in coeffsD2:
assert_(c.dtype == dt_out, "wavedec2: " + errmsg)
x_roundtrip = pywt.waverec2([cA, coeffsD2, coeffsD1], wavelet)
assert_(x_roundtrip.dtype == dt_out, "waverec2: " + errmsg)
示例7: recon
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [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
示例8: _rmatvec
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [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
示例9: get_image
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def get_image(coefs_list):
x = np.zeros((64, 64, 3))
for i in range(3):
x[:, :, i] = pywt.waverec2(coefs_list[i], 'db1')
return x
示例10: test_waverec2_accuracies
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_waverec2_accuracies():
rstate = np.random.RandomState(1234)
x0 = rstate.randn(4, 4)
for dt, tol in dtypes_and_tolerances:
x = x0.astype(dt)
if np.iscomplexobj(x):
x += 1j*rstate.randn(4, 4).astype(x.real.dtype)
coeffs = pywt.wavedec2(x, 'db1')
assert_(len(coeffs) == 3)
assert_allclose(pywt.waverec2(coeffs, 'db1'), x, atol=tol, rtol=tol)
示例11: test_waverec2_all_wavelets_modes
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_waverec2_all_wavelets_modes():
# test 2D case using all wavelets and modes
rstate = np.random.RandomState(1234)
r = rstate.randn(80, 96)
for wavelet in wavelist:
for mode in pywt.Modes.modes:
coeffs = pywt.wavedec2(r, wavelet, mode=mode)
assert_allclose(pywt.waverec2(coeffs, wavelet, mode=mode),
r, rtol=tol_single, atol=tol_single)
示例12: test_wavedec2_complex
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_wavedec2_complex():
data = np.ones((4, 4)) + 1j
coeffs = pywt.wavedec2(data, 'db1')
assert_(len(coeffs) == 3)
assert_allclose(pywt.waverec2(coeffs, 'db1'), data, rtol=1e-12)
示例13: test_waverec2_invalid_inputs
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_waverec2_invalid_inputs():
# input must be list or tuple
assert_raises(ValueError, pywt.waverec2, np.ones((8, 8)), 'haar')
# input list cannot be empty
assert_raises(ValueError, pywt.waverec2, [], 'haar')
示例14: test_waverec2_odd_length
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_waverec2_odd_length():
x = np.ones((10, 6))
coeffs = pywt.wavedec2(x, 'db1')
assert_allclose(pywt.waverec2(coeffs, 'db1'), x, rtol=1e-12)
示例15: test_waverec2_none_coeffs
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverec2 [as 别名]
def test_waverec2_none_coeffs():
x = np.arange(24).reshape(6, 4)
coeffs = pywt.wavedec2(x, 'db1')
coeffs[1] = (None, None, None)
assert_(x.shape == pywt.waverec2(coeffs, 'db1').shape)
####
# nd multilevel dwt function tests
####