PyTorch-Wavelet-Toolbox icon indicating copy to clipboard operation
PyTorch-Wavelet-Toolbox copied to clipboard

3D Matrix Wavelet Decomposition

Open johnryan465 opened this issue 2 years ago • 3 comments

I have a specific application where the sparse matrix representation of the DWT is really useful for a 3D signals. I'd like to propose it as an enhancement.

johnryan465 avatar Aug 26 '22 08:08 johnryan465

Yes, we currently do not support sparse matrix transforms in 3D. I agree it would be very nice to have.

v0lta avatar Aug 26 '22 12:08 v0lta

This is going to be a big project. The last time I checked, PyTorch did not provide a sparse QR solver. We already have a gram-Schmitt alternative implemented, but it's not in CUDA and is slow. It works in the 2D case, but I expect 3D matrices to be bigger and sparser. Personally, this is something I will look at when I have an extended time block available in the future.

v0lta avatar Aug 30 '22 08:08 v0lta

As always, contributions are welcome.

v0lta avatar Aug 30 '22 09:08 v0lta

Dear @johnryan465 , after installing the most recent release candidate via,

pip install git+ssh://[email protected]/v0lta/[email protected]

you should be able to run the following:

import ptwt, torch, pywt
import numpy as np
data = torch.rand(2, 32, 32, 32).type(torch.float64)
matrixfwt = ptwt.MatrixWavedec3(pywt.Wavelet("haar"), level=2)
mat_coeff = matrixfwt(data)
matrixifwt = ptwt.MatrixWaverec3(pywt.Wavelet("haar"))
reconstruction = matrixifwt(mat_coeff)

np.allclose(reconstruction.numpy(), data.numpy())

which computes and inverts a separable sparse matrix boundary 3d-dwt.

v0lta avatar Dec 30 '22 23:12 v0lta