Inverse Fast Wavelet Transform (iFWT) using padded convolutions#

1d reconstruction using waverec()#

ptwt.waverec(coeffs: Sequence[Tensor], wavelet: Wavelet | str, axis: int = -1) Tensor[source]#

Reconstruct a 1d signal from wavelet coefficients.

Parameters:
  • coeffs – The wavelet coefficient sequence produced by the forward transform wavedec(). See ptwt.constants.WaveletCoeff1d.

  • wavelet (Wavelet or str) – A pywt wavelet compatible object or the name of a pywt wavelet. Refer to the output from pywt.wavelist(kind='discrete') for possible choices.

  • axis (int) – Compute the transform over this axis of the data tensor. Defaults to -1.

Returns:

The reconstructed signal tensor. Its shape depends on the shape of the input to ptwt.wavedec().

Example

>>> import ptwt, torch
>>> # generate an input of even length.
>>> data = torch.arange(8, dtype=torch.float32)
>>> # invert the fast wavelet transform.
>>> coefficients = ptwt.wavedec(data, 'haar', mode='zero', level=2)
>>> ptwt.waverec(coefficients, "haar")

2d reconstruction using waverec2()#

ptwt.waverec2(coeffs: ptwt.constants.WaveletCoeff2d, wavelet: Wavelet | str, axes: tuple[int, int] = (-2, -1)) Tensor[source]#

Reconstruct a 2d signal from wavelet coefficients.

Parameters:
  • coeffs – The wavelet coefficient tuple produced by ptwt.wavedec2(). See ptwt.constants.WaveletCoeff2d

  • wavelet (Wavelet or str) – A pywt wavelet compatible object or the name of a pywt wavelet. Refer to the output from pywt.wavelist(kind='discrete') for possible choices.

  • axes (tuple[int, int]) – Compute the transform over these axes of the data tensor. Defaults to (-2, -1).

Returns:

The reconstructed signal tensor. Its shape depends on the shape of the input to ptwt.wavedec2().

Raises:

ValueError – If coeffs is not in a shape as returned from ptwt.wavedec2() or if the dtype is not supported or if the provided axes input has length other than two or if the same axes it repeated twice.

Example

>>> import ptwt, torch
>>> from scipy import datasets
>>> data = torch.tensor(datasets.face(), dtype=torch.float64)
>>> # permute [H, W, C] -> [C, H, W]
>>> data = data.permute(2, 0, 1)
>>> # compute the forward fwt coefficients and the reconstruction
>>> coefficients = ptwt.wavedec2(data, "haar", level=2, mode="constant")
>>> reconstruction = ptwt.waverec2(coefficients, "haar")

3d reconstruction using waverec3()#

ptwt.waverec3(coeffs: ptwt.constants.WaveletCoeffNd, wavelet: Wavelet | str, axes: tuple[int, int, int] = (-3, -2, -1)) Tensor[source]#

Reconstruct a 3d signal from wavelet coefficients.

Parameters:
  • coeffs – The wavelet coefficient tuple produced by ptwt.wavedec3(), see ptwt.constants.WaveletCoeffNd.

  • wavelet (Wavelet or str) – A pywt wavelet compatible object or the name of a pywt wavelet. Refer to the output from pywt.wavelist(kind='discrete') for possible choices.

  • axes (tuple[int, int, int]) – Compute the transform over these axes of the data tensor. Defaults to (-3, -2, -1).

Returns:

The reconstructed signal tensor. Its shape depends on the shape of the input to ptwt.wavedec3().

Raises:

ValueError – If coeffs is not in a shape as returned from ptwt.wavedec3() or if the dtype is not supported or if the provided axes input has length other than three or if the same axes it repeated three.

Example

>>> import ptwt, torch
>>> data = torch.randn(5, 16, 16, 16)
>>> transformed = ptwt.wavedec3(data, "haar", level=2, mode="reflect")
>>> reconstruction = ptwt.waverec3(transformed, "haar")

Fully separable 2d reconstruction using fswaverec2()#

ptwt.fswaverec2(coeffs: ptwt.constants.WaveletCoeff2dSeparable, wavelet: Wavelet | str, axes: tuple[int, int] = (-2, -1)) Tensor[source]#

Compute a fully separable 2D-padded synthesis wavelet transform.

Single-dimensional convolutions are used to transform each axis individually. Under the hood, all dimensions are transformed using torch.nn.functional.conv1d().

Parameters:
  • coeffs – The wavelet coefficients as computed by ptwt.fswavedec2(), see ptwt.constants.WaveletCoeff2dSeparable.

  • wavelet (Wavelet or str) – A pywt wavelet compatible object or the name of a pywt wavelet. Refer to the output from pywt.wavelist(kind='discrete') for possible choices.

  • axes (tuple[int, int]) – Compute the transform over these axes of the data tensor. Defaults to (-2, -1).

Returns:

A reconstruction of the signal encoded in the wavelet coefficients. Its shape depends on the shape of the input to ptwt.fswavedec2().

Example

>>> import ptwt, torch
>>> data = torch.randn(5, 10, 10)
>>> coeff = ptwt.fswavedec2(data, "haar", level=2)
>>> rec = ptwt.fswaverec2(coeff, "haar")

Fully separable 3d reconstruction using fswaverec3()#

ptwt.fswaverec3(coeffs: ptwt.constants.WaveletCoeffNd, wavelet: Wavelet | str, axes: tuple[int, int, int] = (-3, -2, -1)) Tensor[source]#

Compute a fully separable 3D-padded synthesis wavelet transform.

Single-dimensional convolutions are used to transform each axis individually. Under the hood, all dimensions are transformed using torch.nn.functional.conv1d().

Parameters:
  • coeffs – The wavelet coefficients as computed by ptwt.fswavedec3(), see ptwt.constants.WaveletCoeffNd.

  • wavelet (Wavelet or str) – A pywt wavelet compatible object or the name of a pywt wavelet. Refer to the output from pywt.wavelist(kind='discrete') for possible choices.

  • axes (tuple[int, int, int]) – Compute the transform over these axes of the data tensor. Defaults to (-3, -2, -1).

Returns:

A reconstruction of the signal encoded in the wavelet coefficients. Its shape depends on the shape of the input to ptwt.fswavedec3().

Example

>>> import ptwt, torch
>>> data = torch.randn(5, 10, 10, 10)
>>> coeff = ptwt.fswavedec3(data, "haar", level=2)
>>> rec = ptwt.fswaverec3(coeff, "haar")