当前位置: 首页>>代码示例>>Python>>正文


Python pywt.wavedec2方法代码示例

本文整理汇总了Python中pywt.wavedec2方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.wavedec2方法的具体用法?Python pywt.wavedec2怎么用?Python pywt.wavedec2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pywt的用法示例。


在下文中一共展示了pywt.wavedec2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_basis

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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 
开发者ID:AshishBora,项目名称:csgm,代码行数:27,代码来源:wavelet_basis.py

示例2: compute_wavelet_feature_vector

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:21,代码来源:wavelets.py

示例3: test_coeffs_to_array

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [as 别名]
def test_coeffs_to_array():
    # single element list returns the first element
    a_coeffs = [np.arange(8).reshape(2, 4), ]
    arr, arr_slices = pywt.coeffs_to_array(a_coeffs)
    assert_allclose(arr, a_coeffs[0])
    assert_allclose(arr, arr[arr_slices[0]])

    assert_raises(ValueError, pywt.coeffs_to_array, [])
    # invalid second element:  array as in wavedec, but not 1D
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs[0], ] * 2)
    # invalid second element:  tuple as in wavedec2, but not a 3-tuple
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs[0],
                                                     (a_coeffs[0], )])
    # coefficients as None is not supported
    assert_raises(ValueError, pywt.coeffs_to_array, [None, ])
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs,
                                                     (None, None, None)])

    # invalid type for second coefficient list element
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs, None])

    # use an invalid key name in the coef dictionary
    coeffs = [np.array([0]), dict(d=np.array([0]), c=np.array([0]))]
    assert_raises(ValueError, pywt.coeffs_to_array, coeffs) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:26,代码来源:test_multilevel.py

示例4: test_wavedecn_coeff_reshape_even

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:27,代码来源:test_multilevel.py

示例5: _assert_all_coeffs_equal

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [as 别名]
def _assert_all_coeffs_equal(coefs1, coefs2):
    # return True only if all coefficients of SWT or DWT match over all levels
    if len(coefs1) != len(coefs2):
        return False
    for (c1, c2) in zip(coefs1, coefs2):
        if isinstance(c1, tuple):
            # for swt, swt2, dwt, dwt2, wavedec, wavedec2
            for a1, a2 in zip(c1, c2):
                assert_array_equal(a1, a2)
        elif isinstance(c1, dict):
            # for swtn, dwtn, wavedecn
            for k, v in c1.items():
                assert_array_equal(v, c2[k])
        else:
            return False
    return True 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:18,代码来源:test_concurrent.py

示例6: fusion

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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 
开发者ID:pfchai,项目名称:ImageFusion,代码行数:25,代码来源:fusion_dwb.py

示例7: generate_basis

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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 
开发者ID:ermongroup,项目名称:sparse_gen,代码行数:27,代码来源:wavelet_basis.py

示例8: __init__

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [as 别名]
def __init__(self,nrow=256,ncol=256,wavelet='db4',level=3,fwd_mode='recon',\
        dtype=np.float64,name=None):

        # Save parameters
        self.wavelet = wavelet
        self.level = level
        shape0 = (nrow,ncol)
        shape1 = (nrow,ncol)
        dtype0 = dtype
        dtype1 = dtype

        if pywt.Wavelet(wavelet).orthogonal:
            svd_avail = True #SVD calculation assumes an orthogonal wavelet
        else:
            svd_avail = False
        BaseLinTrans.__init__(self, shape0, shape1, dtype0, dtype1,\
           svd_avail=svd_avail,name=name)


        # Set the mode to periodic to make the wavelet orthogonal
        self.mode = 'periodization'

        # Send a zero image to get the coefficient slices
        im = np.zeros((nrow,ncol))
        coeffs = pywt.wavedec2(im, wavelet=self.wavelet, level=self.level, \
            mode=self.mode)
        _, self.coeff_slices = pywt.coeffs_to_array(coeffs)


        # Confirm that fwd_mode is valid
        if (fwd_mode != 'recon') and (fwd_mode != 'analysis'):
            raise common.VpException('fwd_mode must be recon or analysis')
        self.fwd_mode = fwd_mode 
开发者ID:GAMPTeam,项目名称:vampyre,代码行数:35,代码来源:wavelet.py

示例9: analysis

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [as 别名]
def analysis(self,z0):
        """
        Analysis:  image -> coefficients
        """
        coeffs = pywt.wavedec2(z0, wavelet=self.wavelet, level=self.level, \
            mode=self.mode)
        z1, _ = pywt.coeffs_to_array(coeffs)
        return z1 
开发者ID:GAMPTeam,项目名称:vampyre,代码行数:10,代码来源:wavelet.py

示例10: recon

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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 
开发者ID:GAMPTeam,项目名称:vampyre,代码行数:10,代码来源:wavelet.py

示例11: get_wavelet

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [as 别名]
def get_wavelet(x):
    coefs_list = []
    for i in range(3):
        coefs_list.append(pywt.wavedec2(x[:, :, i], 'db1'))
    return coefs_list 
开发者ID:AshishBora,项目名称:csgm,代码行数:7,代码来源:celebA_estimators.py

示例12: wavelet_transform

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [as 别名]
def wavelet_transform(x):
    w_coeffs_rgb = [] # np.zeros(x.shape[3], np.prod(x.shape))
    for i in range(x.shape[3]):
        w_coeffs_list = pywt.wavedec2(x[0,:,:,i], 'db4', level=None, mode='periodization')
        w_coeffs, coeff_slices = pywt.coeffs_to_array(w_coeffs_list)
        w_coeffs_rgb.append(w_coeffs)

    w_coeffs_rgb = np.array(w_coeffs_rgb)
    return w_coeffs_rgb, coeff_slices 
开发者ID:rick-chang,项目名称:OneNet,代码行数:11,代码来源:solver_l1.py

示例13: test_waverec2_accuracies

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:12,代码来源:test_multilevel.py

示例14: test_multilevel_dtypes_2d

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:16,代码来源:test_multilevel.py

示例15: test_waverec2_all_wavelets_modes

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec2 [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) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:11,代码来源:test_multilevel.py


注:本文中的pywt.wavedec2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。