[SciPy-user] multidimensional wavelet packages

Filip Wasilewski filipwasilewski@gmail....
Wed Jan 14 18:50:44 CST 2009

```Hi Karl,

On Thu, Jan 8, 2009 at 02:29, Karl Young <Karl.Young@ucsf.edu> wrote:
>
> Hi Filip,
>
> Thanks much (and thanks for the original package); I will go through the
> code and let you know if I come up with anything that would be worth
> incorporating (or let you know that your suggested addition works fine
> and should be added as is).
>
>>Hi Karl,
>>
>>On Wed, Jan 7, 2009 at 22:15, Karl Young <Karl.Young@ucsf.edu> wrote:
>>
>>
>>>Hi Stefan,
>>>
>>>Thanks; I'd looked a little at PyWavelets and figured that what you
>>>suggest might be what I ended up hacking but thought maybe some
>>>enterprising neuroimager (or other person working with 3D, 4D data)
>>>might have already done so :-)

Guess what. I have forgot that some time ago I already implemented the
proper `downcoef` routine in PyWavelets svn version. Below is an
updated recipe for n-dimensional 1-level dwt:

<code>
#!/usr/bin/env python
# Author: Filip Wasilewski
# Licence: Public Domain

import numpy
import pywt

def downcoef(data, wavelet, mode, type):
return pywt.downcoef(type, data, wavelet, mode, level=1)

def dwt_n(data, wavelet, mode='sym'):
"""N-dimensional Discrete Wavelet Transform"""
data = numpy.asarray(data)
dim = len(data.shape)
coeffs = [('', data)]
for axis in range(dim):
new_coeffs = []
for subband, x in coeffs:
new_coeffs.extend([
(subband+'L', numpy.apply_along_axis(downcoef, axis, x,
wavelet, mode, 'a')),
(subband+'H', numpy.apply_along_axis(downcoef, axis, x,
wavelet, mode, 'd'))
])
coeffs = new_coeffs
return dict(coeffs)

if __name__ == '__main__':
import pprint
data = numpy.ones((4, 4, 4, 4)) # 4D array
result = dwt_n(data , 'db1')
pprint.pprint(result)

</code>

Filip Wasilewski
--