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?

4

2 回答 2

0

我刚刚发生了同样的错误。这是由于您使用的数组的大小:因为它不能被 2 整除,所以函数给出的最大级别数:

pywt.swt_max_level

是 0。例如,这个:

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

为我工作。

于 2017-05-03T16:34:54.403 回答
0

来自pywt.swtn 文档页面上的“注释”

.... 要求沿变换轴的信号长度是 2**level 的倍数。如果不是这种情况,用户应该使用 numpy.pad 等函数填充到适当的大小。

在您的情况下,第三轴的尺寸应该是 2 的倍数。

于 2021-05-25T02:16:21.390 回答