pierrepaleo / pypwt

A Python-CUDA implementation of the Wavelet Transform
Other
24 stars 11 forks source link

forcing nlevels #2

Closed tdr1991 closed 6 years ago

tdr1991 commented 6 years ago

Hi everybody, I have 1D data, the length is 8, level set 3, there is a warning: Forcing nlevels = 2 Warning: required level (3) is greater than the maximum possible level for haar (2) on a 8x1 ima ge.

when the length is 5, level is 2, the warning is : Forcing nlevels = 1 Warning: required level (2) is greater than the maximum possible level for haar (1) on a 5x1 image.

How can I deal with it,thank you。

pierrepaleo commented 6 years ago

Hi @tdr1991 pypwt automatically limits the number of decomposition levels. As the data size is halved at each level, "level" cannot be set arbitrarily. The maximum number for "level" is log2(input_size/(filter_size-1)), it does not seem to be correctly implemented in the underlying PDWT library.

So you are right, maximum level for Haar should be 3 on data with 8 samples.

Thank you for the report, I will fix this.

tdr1991 commented 6 years ago

Hi @pierrepaleo , there is another question: The higher the level, the more like the original data, or the opposite? my experiment is the opposite. screenshot from 2018-10-19 19-40-30

pierrepaleo commented 6 years ago

The Wavelets Transform maps a signal to two sets of coefficients: "approximation coefficients" and "details coefficients". The first gives a coarse approximation as the input signal ; the second somehow indicates how to "compensate" for the approximation error.

The approximation coefficients give a coarser representation as the parameter "level" is increased. So if I understood the question correctly, your insight is right.

NB: In your figures, I see that the wavelets coefficients vector has the same length as the input data, which would mean that you used a stationary transform (do_swt=1).

tdr1991 commented 6 years ago

The approximation coefficients will be decomposed more “details coefficients” as the parameter "level" is increased,so it will more like the input signal,right? I indeed used a stationary transform(do_swt=1) 。

pierrepaleo commented 6 years ago

No, when you increase "level", the approximation coefficient are coarser, i.e less like the input signal. Having more detail coefficients doesn't mean that the representation is more precise. The input signal can always be perfectly reconstructed (up to numerical error) from its coefficients regardless of the value of "level".

Regarding the "similarity" between the input signal and the coefficients, you can make an analogy with a succession of "smoothings". In the case of Haar wavelet :

tdr1991 commented 6 years ago

Ok, thank you very much.

pierrepaleo commented 6 years ago

@tdr1991 The bug should be fixed now (version 0.8.1).

tdr1991 commented 6 years ago

Ok, thank you.