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

Alternating the filters #17

Closed CDitzel closed 3 years ago

CDitzel commented 4 years ago

https://github.com/fbcotter/pytorch_wavelets/blob/52964116161a6f6ba409586e42d7c85f64cb36cb/pytorch_wavelets/dtcwt/lowlevel.py#L147

Hi Fergal,

first of all: Amazing implementation you have done here.

Regarding the references line, shouldnt the highpass outputs remain the same but the lowpass outputs be interchanged so that the other filters apply on the next iteration? Maybe I am missing something here

Also, ist the start from index 2 and 3 in this line

X = torch.cat((X[:,:,:,xe[2::2]], X[:,:,:,xe[3::2]]), dim=1)

due to the fact that

The delay differences must not be swapped, eben when the filters are swapped, so an extra delay of one sample must be included as required ...

given in Selesnicks reference paper?

thank you in advance

fbcotter commented 4 years ago

Hi @CDitzel, thanks for the praise! Sorry it's taken me so long to get back to you.

This part of the code gets a little bit tricky, and I don't know if I can even remember this. I referenced Nick Kingsbury's original implementation a lot as the sample shifts are a little bit painful, especially with padding and remembering that the filters are themselves symmetrical.

These are the 2nd level filters, using the q-shift method: "A dual-tree complex wavelet transform with improved orthogonality and symmetry properties,” in 2000 ICIP.

I think the important part is figure 1 image

I've had a little look just now, but I can't work it out sorry. Perhaps contact Nick directly and he might be able to help out with the sample position logic a bit more?

fbcotter commented 3 years ago

@CDitzel I forgot to say, I also have another partly-tested implementation of the DTCWT based off of Selesnick's matlab implementation in pytorch_wavelets/dtcwt/lowlevel2.py:DTCWTForward2. You may find this one easier to follow than Kingsbury's one (the main one I use). I think I had difficulty getting the two to match up exactly because of the tricky things like sample shifts.

CDitzel commented 3 years ago

Hi Fergal, thank you for the detailed response. Yes I saw that, it follows a more traditional approach coding-wise. I will take a closer look. Did Professor Kingsbury introduce this rather obscure implementation that I was asking about?

fbcotter commented 3 years ago

Yes, it was written in an optimized way, but this makes it somewhat obscure