本文整理汇总了Python中pywt.waverecn函数的典型用法代码示例。如果您正苦于以下问题:Python waverecn函数的具体用法?Python waverecn怎么用?Python waverecn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了waverecn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_waverecn_empty_coeff
def test_waverecn_empty_coeff():
coeffs = [np.ones((2, 2, 2)), {}, {}]
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (8, 8, 8))
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (8, 8, 8))
coeffs = [np.ones((2, 2, 2)), {}, {'daa': np.ones((4, 4, 4))}]
coeffs = [np.ones((2, 2, 2)), {}, {}, {'daa': np.ones((8, 8, 8))}]
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (16, 16, 16))
开发者ID:rgommers,项目名称:pywt,代码行数:9,代码来源:test_multilevel.py
示例2: test_wavedecn_coeff_reshape_axes_subset
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)
开发者ID:rgommers,项目名称:pywt,代码行数:27,代码来源:test_multilevel.py
示例3: test_waverecn
def test_waverecn():
rstate = np.random.RandomState(1234)
# test 1D through 4D cases
for nd in range(1, 5):
x = rstate.randn(*(4, )*nd)
coeffs = pywt.wavedecn(x, 'db1')
assert_(len(coeffs) == 3)
assert_allclose(pywt.waverecn(coeffs, 'db1'), x, rtol=tol_double)
开发者ID:rgommers,项目名称:pywt,代码行数:8,代码来源:test_multilevel.py
示例4: test_waverecn_axes_subsets
def test_waverecn_axes_subsets():
rstate = np.random.RandomState(0)
data = rstate.standard_normal((8, 8, 8, 8))
# test all combinations of 3 out of 4 axes transformed
for axes in combinations((0, 1, 2, 3), 3):
coefs = pywt.wavedecn(data, 'haar', axes=axes)
rec = pywt.waverecn(coefs, 'haar', axes=axes)
assert_allclose(rec, data, atol=1e-14)
开发者ID:rgommers,项目名称:pywt,代码行数:8,代码来源:test_multilevel.py
示例5: test_waverecn_int_axis
def test_waverecn_int_axis():
# waverecn should also work for axes as an integer
rstate = np.random.RandomState(0)
data = rstate.standard_normal((8, 8))
for axis in [0, 1]:
coefs = pywt.wavedecn(data, 'haar', axes=axis)
rec = pywt.waverecn(coefs, 'haar', axes=axis)
assert_allclose(rec, data, atol=1e-14)
开发者ID:rgommers,项目名称:pywt,代码行数:8,代码来源:test_multilevel.py
示例6: test_waverecn_all_wavelets_modes
def test_waverecn_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.wavedecn(r, wavelet, mode=mode)
assert_allclose(pywt.waverecn(coeffs, wavelet, mode=mode),
r, rtol=tol_single, atol=tol_single)
开发者ID:rgommers,项目名称:pywt,代码行数:9,代码来源:test_multilevel.py
示例7: _wavelet_threshold
def _wavelet_threshold(img, wavelet, threshold=None, sigma=None, mode='soft'):
"""Performs wavelet denoising.
Parameters
----------
img : ndarray (2d or 3d) of ints, uints or floats
Input data to be denoised. `img` can be of any numeric type,
but it is cast into an ndarray of floats for the computation
of the denoised image.
wavelet : string
The type of wavelet to perform. Can be any of the options
pywt.wavelist outputs. For example, this may be any of ``{db1, db2,
db3, db4, haar}``.
sigma : float, optional
The standard deviation of the noise. The noise is estimated when sigma
is None (the default) by the method in [2]_.
threshold : float, optional
The thresholding value. All wavelet coefficients less than this value
are set to 0. The default value (None) uses the SureShrink method found
in [1]_ to remove noise.
mode : {'soft', 'hard'}, optional
An optional argument to choose the type of denoising performed. It
noted that choosing soft thresholding given additive noise finds the
best approximation of the original image.
Returns
-------
out : ndarray
Denoised image.
References
----------
.. [1] Chang, S. Grace, Bin Yu, and Martin Vetterli. "Adaptive wavelet
thresholding for image denoising and compression." Image Processing,
IEEE Transactions on 9.9 (2000): 1532-1546.
DOI: 10.1109/83.862633
.. [2] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation
by wavelet shrinkage." Biometrika 81.3 (1994): 425-455.
DOI: 10.1093/biomet/81.3.425
"""
coeffs = pywt.wavedecn(img, wavelet=wavelet)
detail_coeffs = coeffs[-1]['d' * img.ndim]
if sigma is None:
# Estimates via the noise via method in [2]
sigma = np.median(np.abs(detail_coeffs)) / 0.67448975019608171
if threshold is None:
# The BayesShrink threshold from [1]_ in docstring
threshold = sigma**2 / np.sqrt(max(img.var() - sigma**2, 0))
denoised_detail = [{key: pywt.threshold(level[key], value=threshold,
mode=mode) for key in level} for level in coeffs[1:]]
denoised_root = pywt.threshold(coeffs[0], value=threshold, mode=mode)
denoised_coeffs = [denoised_root] + [d for d in denoised_detail]
return pywt.waverecn(denoised_coeffs, wavelet)
开发者ID:dfcollin,项目名称:scikit-image,代码行数:57,代码来源:_denoise.py
示例8: test_waverecn_accuracies
def test_waverecn_accuracies():
# testing 3D only here
rstate = np.random.RandomState(1234)
x0 = rstate.randn(4, 4, 4)
for dt, tol in dtypes_and_tolerances:
x = x0.astype(dt)
if np.iscomplexobj(x):
x += 1j*rstate.randn(4, 4, 4).astype(x.real.dtype)
coeffs = pywt.wavedecn(x.astype(dt), 'db1')
assert_allclose(pywt.waverecn(coeffs, 'db1'), x, atol=tol, rtol=tol)
开发者ID:rgommers,项目名称:pywt,代码行数:10,代码来源:test_multilevel.py
示例9: test_per_axis_wavelets_and_modes
def test_per_axis_wavelets_and_modes():
# tests seperate wavelet and edge mode for each axis.
rstate = np.random.RandomState(1234)
data = rstate.randn(24, 24, 16)
# wavelet can be a string or wavelet object
wavelets = (pywt.Wavelet('haar'), 'sym2', 'db2')
# The default number of levels should be the minimum over this list
max_levels = [pywt._dwt.dwt_max_level(nd, nf) for nd, nf in
zip(data.shape, wavelets)]
# mode can be a string or a Modes enum
modes = ('symmetric', 'periodization',
pywt._extensions._pywt.Modes.reflect)
coefs = pywt.wavedecn(data, wavelets, modes)
assert_allclose(pywt.waverecn(coefs, wavelets, modes), data, atol=1e-14)
assert_equal(min(max_levels), len(coefs[1:]))
coefs = pywt.wavedecn(data, wavelets[:1], modes)
assert_allclose(pywt.waverecn(coefs, wavelets[:1], modes), data,
atol=1e-14)
coefs = pywt.wavedecn(data, wavelets, modes[:1])
assert_allclose(pywt.waverecn(coefs, wavelets, modes[:1]), data,
atol=1e-14)
# length of wavelets or modes doesn't match the length of axes
assert_raises(ValueError, pywt.wavedecn, data, wavelets[:2])
assert_raises(ValueError, pywt.wavedecn, data, wavelets, mode=modes[:2])
assert_raises(ValueError, pywt.waverecn, coefs, wavelets[:2])
assert_raises(ValueError, pywt.waverecn, coefs, wavelets, mode=modes[:2])
# dwt2/idwt2 also support per-axis wavelets/modes
data2 = data[..., 0]
coefs2 = pywt.wavedec2(data2, wavelets[:2], modes[:2])
assert_allclose(pywt.waverec2(coefs2, wavelets[:2], modes[:2]), data2,
atol=1e-14)
assert_equal(min(max_levels[:2]), len(coefs2[1:]))
开发者ID:HenryZhou1002,项目名称:pywt,代码行数:40,代码来源:test_multilevel.py
示例10: test_multilevel_dtypes_nd
def test_multilevel_dtypes_nd():
wavelet = pywt.Wavelet('haar')
for dt_in, dt_out in zip(dtypes_in, dtypes_out):
# wavedecn, waverecn
x = np.ones((8, 8), dtype=dt_in)
errmsg = "wrong dtype returned for {0} input".format(dt_in)
cA, coeffsD2, coeffsD1 = pywt.wavedecn(x, wavelet, level=2)
assert_(cA.dtype == dt_out, "wavedecn: " + errmsg)
for key, c in coeffsD1.items():
assert_(c.dtype == dt_out, "wavedecn: " + errmsg)
for key, c in coeffsD2.items():
assert_(c.dtype == dt_out, "wavedecn: " + errmsg)
x_roundtrip = pywt.waverecn([cA, coeffsD2, coeffsD1], wavelet)
assert_(x_roundtrip.dtype == dt_out, "waverecn: " + errmsg)
开发者ID:rgommers,项目名称:pywt,代码行数:14,代码来源:test_multilevel.py
示例11: PrintReconstructions
def PrintReconstructions(coeffs, n):
arr, coeff_slices = pywt.coeffs_to_array(coeffs)
#Removing Details
for i in range(n,len(coeff_slices)):
arr[coeff_slices[i]['ad']] = 0
arr[coeff_slices[i]['dd']] = 0
arr[coeff_slices[i]['da']] = 0
D1 = pywt.array_to_coeffs(arr, coeff_slices)
dCat = pywt.waverecn(D1, wavelet)
plt.figure()
plt.title('Reconstructed with level %i of details' %(n-1))
plt.imshow(dCat,cmap=colormap)
return
开发者ID:MatheusNali,项目名称:WavePySeminar,代码行数:16,代码来源:PyWavelets.py
示例12: test_waverecn_coeff_reshape_odd
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)
开发者ID:rgommers,项目名称:pywt,代码行数:18,代码来源:test_multilevel.py
示例13: test_wavedecn_complex
def test_wavedecn_complex():
data = np.ones((4, 4, 4)) + 1j
coeffs = pywt.wavedecn(data, 'db1')
assert_allclose(pywt.waverecn(coeffs, 'db1'), data, rtol=1e-12)
开发者ID:rgommers,项目名称:pywt,代码行数:4,代码来源:test_multilevel.py
示例14: inverse_wavelet_transform
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
开发者ID:githublzb,项目名称:OneNet,代码行数:6,代码来源:solver_l1.py
示例15: apply_dwt_filter
def apply_dwt_filter(y, dwt_type, dwt_level, dwt_thresh_func, dwt_thresh_type):
coeffs = pywt.wavedecn(y, dwt_type, level=dwt_level)
for i in range(1,dwt_level+1):
coeffs[i]["d"] = pywt.threshold(coeffs[i]["d"], thselect(coeffs[i]["d"], dwt_thresh_type), dwt_thresh_func)
return(pywt.waverecn(coeffs, dwt_type))
开发者ID:eduardo-elizondo,项目名称:eeg_modeling,代码行数:5,代码来源:datafilters.py
示例16: time_waverecn
def time_waverecn(self, D, n, wavelet, dtype):
pywt.waverecn(self.data, wavelet)
开发者ID:HenryZhou1002,项目名称:pywt,代码行数:2,代码来源:dwt_benchmarks.py
示例17: test_waverecn_lists
def test_waverecn_lists():
# support coefficient arrays specified as lists instead of arrays
coeffs = [[[1.0]], {'ad': [[0.0]], 'da': [[0.0]], 'dd': [[0.0]]}]
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (2, 2))
开发者ID:rgommers,项目名称:pywt,代码行数:4,代码来源:test_multilevel.py
示例18: _wavelet_threshold
#.........这里部分代码省略.........
pywt.wavelist outputs. For example, this may be any of ``{db1, db2,
db3, db4, haar}``.
method : {'BayesShrink', 'VisuShrink'}, optional
Thresholding method to be used. The currently supported methods are
"BayesShrink" [1]_ and "VisuShrink" [2]_. If it is set to None, a
user-specified ``threshold`` must be supplied instead.
threshold : float, optional
The thresholding value to apply during wavelet coefficient
thresholding. The default value (None) uses the selected ``method`` to
estimate appropriate threshold(s) for noise removal.
sigma : float, optional
The standard deviation of the noise. The noise is estimated when sigma
is None (the default) by the method in [2]_.
mode : {'soft', 'hard'}, optional
An optional argument to choose the type of denoising performed. It
noted that choosing soft thresholding given additive noise finds the
best approximation of the original image.
wavelet_levels : int or None, optional
The number of wavelet decomposition levels to use. The default is
three less than the maximum number of possible decomposition levels
(see Notes below).
Returns
-------
out : ndarray
Denoised image.
References
----------
.. [1] Chang, S. Grace, Bin Yu, and Martin Vetterli. "Adaptive wavelet
thresholding for image denoising and compression." Image Processing,
IEEE Transactions on 9.9 (2000): 1532-1546.
:DOI:`10.1109/83.862633`
.. [2] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation
by wavelet shrinkage." Biometrika 81.3 (1994): 425-455.
:DOI:`10.1093/biomet/81.3.425`
"""
wavelet = pywt.Wavelet(wavelet)
if not wavelet.orthogonal:
warn(("Wavelet thresholding was designed for use with orthogonal "
"wavelets. For nonorthogonal wavelets such as {}, results are "
"likely to be suboptimal.").format(wavelet.name))
# original_extent is used to workaround PyWavelets issue #80
# odd-sized input results in an image with 1 extra sample after waverecn
original_extent = tuple(slice(s) for s in image.shape)
# Determine the number of wavelet decomposition levels
if wavelet_levels is None:
# Determine the maximum number of possible levels for image
dlen = wavelet.dec_len
wavelet_levels = np.min(
[pywt.dwt_max_level(s, dlen) for s in image.shape])
# Skip coarsest wavelet scales (see Notes in docstring).
wavelet_levels = max(wavelet_levels - 3, 1)
coeffs = pywt.wavedecn(image, wavelet=wavelet, level=wavelet_levels)
# Detail coefficients at each decomposition level
dcoeffs = coeffs[1:]
if sigma is None:
# Estimate the noise via the method in [2]_
detail_coeffs = dcoeffs[-1]['d' * image.ndim]
sigma = _sigma_est_dwt(detail_coeffs, distribution='Gaussian')
if method is not None and threshold is not None:
warn(("Thresholding method {} selected. The user-specified threshold "
"will be ignored.").format(method))
if threshold is None:
var = sigma**2
if method is None:
raise ValueError(
"If method is None, a threshold must be provided.")
elif method == "BayesShrink":
# The BayesShrink thresholds from [1]_ in docstring
threshold = [{key: _bayes_thresh(level[key], var) for key in level}
for level in dcoeffs]
elif method == "VisuShrink":
# The VisuShrink thresholds from [2]_ in docstring
threshold = _universal_thresh(image, sigma)
else:
raise ValueError("Unrecognized method: {}".format(method))
if np.isscalar(threshold):
# A single threshold for all coefficient arrays
denoised_detail = [{key: pywt.threshold(level[key],
value=threshold,
mode=mode) for key in level}
for level in dcoeffs]
else:
# Dict of unique threshold coefficients for each detail coeff. array
denoised_detail = [{key: pywt.threshold(level[key],
value=thresh[key],
mode=mode) for key in level}
for thresh, level in zip(threshold, dcoeffs)]
denoised_coeffs = [coeffs[0]] + denoised_detail
return pywt.waverecn(denoised_coeffs, wavelet)[original_extent]
开发者ID:jarrodmillman,项目名称:scikit-image,代码行数:101,代码来源:_denoise.py
示例19: test_waverecn_dtypes
def test_waverecn_dtypes():
x = np.ones((4, 4, 4))
for dt, tol in dtypes_and_tolerances:
coeffs = pywt.wavedecn(x.astype(dt), 'db1')
assert_allclose(pywt.waverecn(coeffs, 'db1'), x, atol=tol, rtol=tol)
开发者ID:rgommers,项目名称:pywt,代码行数:5,代码来源:test_multilevel.py
示例20: _wavelet_threshold
def _wavelet_threshold(img, wavelet, threshold=None, sigma=None, mode='soft',
wavelet_levels=None):
"""Perform wavelet denoising.
Parameters
----------
img : ndarray (2d or 3d) of ints, uints or floats
Input data to be denoised. `img` can be of any numeric type,
but it is cast into an ndarray of floats for the computation
of the denoised image.
wavelet : string
The type of wavelet to perform. Can be any of the options
pywt.wavelist outputs. For example, this may be any of ``{db1, db2,
db3, db4, haar}``.
sigma : float, optional
The standard deviation of the noise. The noise is estimated when sigma
is None (the default) by the method in [2]_.
threshold : float, optional
The thresholding value. All wavelet coefficients less than this value
are set to 0. The default value (None) uses the BayesShrink method
found in [1]_ to remove noise.
mode : {'soft', 'hard'}, optional
An optional argument to choose the type of denoising performed. It
noted that choosing soft thresholding given additive noise finds the
best approximation of the original image.
wavelet_levels : int or None, optional
The number of wavelet decomposition levels to use. The default is
three less than the maximum number of possible decomposition levels
(see Notes below).
Returns
-------
out : ndarray
Denoised image.
Notes
-----
Reference [1]_ used four levels of wavelet decomposition. To be more
flexible for a range of input sizes, the implementation here stops 3 levels
prior to the maximum level of decomposition for `img` (the exact # of
levels thus depends on `img.shape` and the chosen wavelet). BayesShrink
variance estimation doesn't work well on levels with extremely small
coefficient arrays. This is the rationale for skipping a few of the
coarsest levels. The user can override the automated setting by explicitly
specifying `wavelet_levels`.
References
----------
.. [1] Chang, S. Grace, Bin Yu, and Martin Vetterli. "Adaptive wavelet
thresholding for image denoising and compression." Image Processing,
IEEE Transactions on 9.9 (2000): 1532-1546.
DOI: 10.1109/83.862633
.. [2] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation
by wavelet shrinkage." Biometrika 81.3 (1994): 425-455.
DOI: 10.1093/biomet/81.3.425
"""
wavelet = pywt.Wavelet(wavelet)
# Determine the number of wavelet decomposition levels
if wavelet_levels is None:
# Determine the maximum number of possible levels for img
dlen = wavelet.dec_len
wavelet_levels = np.min(
[pywt.dwt_max_level(s, dlen) for s in img.shape])
# Skip coarsest wavelet scales (see Notes in docstring).
wavelet_levels = max(wavelet_levels - 3, 1)
coeffs = pywt.wavedecn(img, wavelet=wavelet, level=wavelet_levels)
# Detail coefficients at each decomposition level
dcoeffs = coeffs[1:]
if sigma is None:
# Estimate the noise via the method in [2]_
detail_coeffs = dcoeffs[-1]['d' * img.ndim]
sigma = _sigma_est_dwt(detail_coeffs, distribution='Gaussian')
if threshold is None:
# The BayesShrink thresholds from [1]_ in docstring
var = sigma**2
threshold = [{key: _bayes_thresh(level[key], var) for key in level}
for level in dcoeffs]
if np.isscalar(threshold):
# A single threshold for all coefficient arrays
denoised_detail = [{key: pywt.threshold(level[key],
value=threshold,
mode=mode) for key in level}
for level in dcoeffs]
else:
# Dict of unique threshold coefficients for each detail coeff. array
denoised_detail = [{key: pywt.threshold(level[key],
value=thresh[key],
mode=mode) for key in level}
for thresh, level in zip(threshold, dcoeffs)]
denoised_coeffs = [coeffs[0]] + denoised_detail
return pywt.waverecn(denoised_coeffs, wavelet)
开发者ID:ameya005,项目名称:scikit-image,代码行数:98,代码来源:_denoise.py
注:本文中的pywt.waverecn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论