tfmri.signal.wavelet_coeffs_to_tensor

wavelet_coeffs_to_tensor(coeffs, padding=0, axes=None)[source]

Arranges a wavelet coefficient list into a single tensor.

Parameters
  • coeffs – A list of wavelet coefficients as returned by tfmri.signal.wavedec.

  • padding – The value to use for the background if the coefficients cannot be tightly packed. If None, raise an error if the coefficients cannot be tightly packed.

  • axes – Axes over which the DWT that created coeffs was performed. The default value of None corresponds to all axes.

Returns

A tuple (tensor, slices) holding the coefficients tf.Tensor and a list of slices corresponding to each coefficient. For example, in a 2D tensor, tensor[slices[1]['dd']] would extract the first level detail coefficients from tensor.

Raises

ValueError – If passed invalid inputs.

Notes

Assume a 2D coefficient dictionary, c, from a two-level transform.

Then all 2D coefficients will be stacked into a single larger 2D array as follows:

.. code-block::

c[0]

c[1][‘da’]

c[2][‘da’]

c[2][‘dd’]

c[1][‘ad’]

c[1][‘dd’]

c[2][‘ad’]

If the transform was not performed with mode “periodization” or the signal length was not a multiple of ``2**level``, coefficients at each subsequent scale will not be exactly 1/2 the size of those at the previous level due to additional coefficients retained to handle the boundary condition. In these cases, the default setting of padding=0 indicates to pad the individual coefficient arrays with 0 as needed so that they can be stacked into a single, contiguous array.

Examples

>>> import tensorflow_mri as tfmri
>>> image = tfmri.image.phantom()
>>> coeffs = tfmri.signal.wavedec(image, wavelet='db2', level=3)
>>> tensor, slices = tfmri.signal.wavelet_coeffs_to_tensor(coeffs)