2

I've been trying to apply a one-level undecimated wavelets transform to a 3D numpy arrangement using the function swtn from the package pywavelets in python as follows:

import numpy as np
from pywavelts import swtn

img = np.random.rand(4,4,5)
WT = swtn(img, 'coif1', level = 1, start_level = 0) 

which rises an error:

Traceback (most recent call last):

  File "<ipython-input-60-1f6f4144a239>", line 1, in <module>
    pywt.swtn(img, 'coif1', level=1, start_level =0, axes=None)

  File "/usr/local/lib/python2.7/dist-packages/pywt/_swt.py", line 387, in swtn
    axis=axis)[0]

  File "pywt/_extensions/_swt.pyx", line 100, in pywt._extensions._swt.swt_axis (pywt/_extensions/_swt.c:6203)

  File "pywt/_extensions/_swt.pyx", line 116, in pywt._extensions._swt.swt_axis (pywt/_extensions/_swt.c:5035)

ValueError: start_level must be less than 0. 

However, this does not make sense to me since the start level value less than 0 is not allowed by the wavelet decomposition. Could somebody have a look and point me out what I am missing?

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712

2 Answers2

0

I just had the same error occuring. It is due to the size of the array you use: since it is not divisible by 2, the maximum number of levels, given by the function:

pywt.swt_max_level

is 0. For instance, this:

img = np.random.rand(4,4,6)
WT = swtn(img, 'coif1', level = 1, start_level = 0) 

works for me.

0

From "Notes" available on pywt.swtn documentation page

.... requires that the signal length along the transformed axes be a multiple of 2**level. If this is not the case, the user should pad up to an appropriate size using a function such as numpy.pad.

In your case, the dimension of your third axis should be a multiple of 2.

Debvrat Varshney
  • 450
  • 1
  • 7
  • 15