Hi,
I tried the example given in the docs for raveling coefficients in n-D: https://pywavelets.readthedocs.io/en/latest/ref/dwt-coefficient-handling.html#raveling-and-unraveling-coefficients-to-from-a-1d-array .
It works perfectly. However, if I chose to use wavedec2 instead of wavedecn, it fails:
import pywt
from numpy.testing import assert_array_almost_equal
cam = pywt.data.camera()
coeffs = pywt.wavedec2(cam, wavelet='db2', level=3)
arr, coeff_slices, coeff_shapes = pywt.ravel_coeffs(coeffs)
coeffs_from_arr = pywt.unravel_coeffs(arr, coeff_slices, coeff_shapes)
cam_recon = pywt.waverec2(coeffs_from_arr, wavelet='db2')
assert_array_almost_equal(cam, cam_recon)
gives:
ValueError Traceback (most recent call last)
<ipython-input-187-3b8a21e194b7> in <module>
4 arr, coeff_slices, coeff_shapes = pywt.ravel_coeffs(coeffs)
5 coeffs_from_arr = pywt.unravel_coeffs(arr, coeff_slices, coeff_shapes)
----> 6 cam_recon = pywt.waverec2(coeffs_from_arr, wavelet='db2')
7 assert_array_almost_equal(cam, cam_recon)
~/workspace/pysap/venv/lib/python3.5/site-packages/PyWavelets-1.0.1-py3.5-linux-x86_64.egg/pywt/_multilevel.py in waverec2(coeffs, wavelet, mode, axes)
323 idxs = tuple(slice(None, -1 if a_len == d_len + 1 else None)
324 for a_len, d_len in zip(a.shape, d_shape))
--> 325 a = idwt2((a[idxs], d), wavelet, mode, axes)
326
327 return a
~/workspace/pysap/venv/lib/python3.5/site-packages/PyWavelets-1.0.1-py3.5-linux-x86_64.egg/pywt/_multidim.py in idwt2(coeffs, wavelet, mode, axes)
116
117 coeffs = {'aa': LL, 'da': HL, 'ad': LH, 'dd': HH}
--> 118 return idwtn(coeffs, wavelet, mode, axes)
119
120
~/workspace/pysap/venv/lib/python3.5/site-packages/PyWavelets-1.0.1-py3.5-linux-x86_64.egg/pywt/_multidim.py in idwtn(coeffs, wavelet, mode, axes)
275 "band")
276 if any(s != coeff_shape for s in coeff_shapes):
--> 277 raise ValueError("`coeffs` must all be of equal size (or None)")
278
279 if axes is None:
ValueError: `coeffs` must all be of equal size (or None)
After looking into the unraveled coeffs, it appears that some of them are actually dictionary rather than tuple. Example: type(coeffs[1]) == tuple and type(coeffs_from_arr[1]) == dict. I haven't looked much more into it, so it might not be the cause of this, but I guess for the sake of idempotence, this shouldn't be the case. Also it's not the case in n-D.
Hi,
I tried the example given in the docs for raveling coefficients in n-D: https://pywavelets.readthedocs.io/en/latest/ref/dwt-coefficient-handling.html#raveling-and-unraveling-coefficients-to-from-a-1d-array .
It works perfectly. However, if I chose to use
wavedec2instead ofwavedecn, it fails:gives:
After looking into the unraveled coeffs, it appears that some of them are actually dictionary rather than tuple. Example:
type(coeffs[1]) == tupleandtype(coeffs_from_arr[1]) == dict. I haven't looked much more into it, so it might not be the cause of this, but I guess for the sake of idempotence, this shouldn't be the case. Also it's not the case in n-D.