wavelet

Wrappers for PyWavelets.

mr_utils.utils.wavelet.cdf97_2d_forward(x, level, axes=(-2, -1))[source]

Forward 2D Cohen–Daubechies–Feauveau 9/7 wavelet.

Parameters:
  • x (array_like) – 2D signal.
  • level (int) – Decomposition level.
  • axes (tuple, optional) – Axes to perform wavelet decomposition across.
Returns:

  • wavelet_transform (array_like) – The stitched together elements wvlt (see combine_chunks).
  • locations (list) – Indices telling us how we stitched it together so we can take it back apart.

Notes

Returns transform, same shape as input, with locations. Locations is a list of indices instructing cdf97_2d_inverse where the coefficients for each block are located.

Biorthogonal 4/4 is the same as CDF 9/7 according to wikipedia [1].

References

[1]https://en.wikipedia.org/wiki/ Cohen%E2%80%93Daubechies%E2%80%93Feauveau_wavelet#Numbering
mr_utils.utils.wavelet.cdf97_2d_inverse(coeffs, locations, axes=(-2, -1))[source]

Inverse 2D Cohen–Daubechies–Feauveau 9/7 wavelet.

Parameters:
  • coeffs (array_like) – Stitched together wavelet transform.
  • locations (list) – Output of cdf97_2d_forward().
  • axes (tuple, optional) – Axes to perform wavelet transform across.
Returns:

Inverse CDF97 transform.

Return type:

array_like

mr_utils.utils.wavelet.combine_chunks(wvlt, shape, dtype=<class 'float'>)[source]

Stitch together the output of PyWavelets wavedec2.

Parameters:
  • wvlt (list of array_like) – Output of pywt.wavedec2().
  • shape (tuple) – Desired shape.
  • dtype (np.dtype, optional) – Type of numpy array.
Returns:

  • wavelet_transform (array_like) – The stitched together elements wvlt (see notes).
  • locations (list) – Indices telling us how we stitched it together so we can take it back apart.

Notes

We have tuples that look like this:
                            -------------------
                            |        |        |
                            | cA(LL) | cH(LH) |
                            |        |        |
(cA, (cH, cV, cD))  <--->   -------------------
                            |        |        |
                            | cV(HL) | cD(HH) |
                            |        |        |
                            -------------------
mr_utils.utils.wavelet.split_chunks(coeffs, locations)[source]

Separate the stitched together transform into blocks again.

Parameters:
  • x (array_like) – Stitched together wavelet transform.
  • locations (list) – Indices where the coefficients for each block are located.
Returns:

coeff_list – List of coefficients of wavelet decomposition (like the output of pywt.wavedec2()).

Return type:

list of array_like

Notes

x, locations are the output of combine_chunks().

mr_utils.utils.wavelet.wavelet_forward(x, wavelet, mode='symmetric', level=None, axes=(-2, -1))[source]

Wrapper for the multilevel 2D discrete wavelet transform.

Parameters:
  • x (array_like) – Input data.
  • wavelet (str) – Wavelet to use.
  • mode (str, optional) – Signal extension mode.
  • level (int, optional) – Decomposition level (must be >= 0).
  • axes (tuple, optional) – Axes over which to compute the DWT.
Returns:

  • wavelet_transform (array_like) – The stitched together elements wvlt (see combine_chunks).
  • locations (list) – Indices telling us how we stitched it together so we can take it back apart.

Notes

See PyWavelets documentation on pywt.wavedec2() for more information.

If level=None (default) then it will be calculated using the dwt_max_level function.

mr_utils.utils.wavelet.wavelet_inverse(coeffs, locations, wavelet, mode='symmetric', axes=(-2, -1))[source]

Wrapper for the multilevel 2D inverse DWT.

Parameters:
  • coeffs (array_like) – Combined coefficients.
  • locations (list) – Indices where the coefficients for each block are located.
  • wavelet (str) – Wavelet to use.
  • mode (str, optional) – Signal extension mode.
  • axes (tuple, optional) – Axes over which to compute the IDWT.
Returns:

Inverse transform of wavelet transform, the original image.

Return type:

array_like

Notes

coeffs, locations are the output of forward().