fbcotter / pytorch_wavelets

Pytorch implementation of 2D Discrete Wavelet (DWT) and Dual Tree Complex Wavelet Transforms (DTCWT) and a DTCWT based ScatterNet
Other
943 stars 146 forks source link

Padding for powers of 2 #36

Closed andreasfloros closed 2 years ago

andreasfloros commented 2 years ago

wtpadding I have noticed that DWT always applies padding, even in the case of perfect powers of 2 (see above). Also, when the input dimensions are odd the inverse has incorrect dimensions as shown in #22 (though it seems this can be fixed by just cropping the result). I think it would be nice if all of the padding and cropping was handled internally.

fbcotter commented 2 years ago

Hi @andreasfloros! Sorry for the late reply, I don't check this as much these days. This is intended, and matches the behaviour of PyWavelets.

For the odd signal length, see my answer in #39 .

For this padding, this is because when you convolve a wavelet of length M with a signal of length N, the output will be N+M-1. This happens before the downsampling, and we want to keep this information on the edges so we can reconstruct the signal later. If it's a problem for you (and I know sometimes it's nice to have everything a power of 2 in deep networks), you could use the db1 wavelet (as that only has length 2), or use the periodization padding mode. Neither are ideal though, db1 wavelets aren't too great, and periodization pads the image on the right with the first column on the left (like what you see in fourier transforms)