PyWavelets / pywt

PyWavelets - Wavelet Transforms in Python
http://pywavelets.readthedocs.org
MIT License
2.03k stars 469 forks source link

Indexing the result of multilevel & multidimensional transforms #103

Open kwohlfahrt opened 9 years ago

kwohlfahrt commented 9 years ago

There have been a few proposals for alternative representations for the output of a transform in #93, and I think this needs some more discussion. It gets rapidly complex, when for example wavelet packet transforms are used.

The following are some examples of weird cases that might need to be accessed:

I can't see any easy solutions to this, but any ideas to discuss would be great.

grlee77 commented 9 years ago

I am +1 on @aaren's TransformResult.array method. I am not sure having a class is of much utility for a simple 1D DWT, but I guess if we go that route for the 2D or nD functions it may make sense to just have all functions return a TransformResult for consistency.

@ThomasA I also have utility functions to convert to and from the array format, but mine is currently configured for the coefficients as returned by the wavedecn function proposed in PR #52 . I have not made those functions part of a PR yet because they are likely not robust to all wavelets / array sizes as is, but I have used it for 2D and 3D with 'haar' and some of the other 'db*' wavelets successfully.

rgommers commented 9 years ago
  • Transform that is approximate in the first dimension, detail in the second
  • Transform that is at the first level approximate in the first dimension, detail in the second, then at the second level detail at the first dimension and detail in the second

I'm not quite sure that I see the problem with these examples. If you know that that's how your transform behaves, you can create the proper output class to put the approximation coefficients for both levels in an approx attribute right?

kwohlfahrt commented 9 years ago

I don't see how an approx attribute will work for the multidimensional case. To specify the transform, it needs to know whether it is approximate or detail in every dimension, since each dimension is independent. Then that needs to happen at every level. So if I have the transform of a 2D signal, does an approx attribute refer to something that's approximate in the first dimension, the second, both, or any of them?

grlee77 commented 9 years ago

I think the TransformResult object should also have a copy of the original shape prior to the transformation. This way problems like the example below could be automatically fixed by truncation to the original shape.

example of current behaviour:

a = np.arange(7)
cA, cD = pywt.dwt(a, 'haar')
a_roundtrip = pywt.idwt(cA, cD, 'haar')

output: a_roundtrip = array([ 0. 1. 2. 3. 4. 5. 6. 6.]) (duplicate last element)