WaveletTransform

class odl.trafos.wavelet.WaveletTransform(*args, **kwargs)[source]

Bases: WaveletTransformBase

Discrete wavelet transform between discretized Lp spaces.

Attributes:
adjoint

Adjoint wavelet transform.

domain

Set of objects on which this operator can be evaluated.

impl

Implementation back-end of this wavelet transform.

inverse

Inverse wavelet transform.

is_biorthogonal

Whether or not the wavelet basis is bi-orthogonal.

is_functional

True if this operator's range is a Field.

is_linear

True if this operator is linear.

is_orthogonal

Whether or not the wavelet basis is orthogonal.

nlevels

Number of scaling levels in this wavelet transform.

pad_const

Value for extension used in 'constant' padding mode.

pad_mode

Padding mode used for extending input beyond its boundary.

range

Set in which the result of an evaluation of this operator lies.

wavelet

Name of the wavelet used in this wavelet transform.

Methods

__call__(x[, out])

Return self(x[, out, **kwargs]).

derivative(point)

Return the operator derivative at point.

norm([estimate])

Return the operator norm of this operator.

scales()

Get the scales of each coefficient.

__init__(domain, wavelet, nlevels=None, pad_mode='constant', pad_const=0, impl='pywt', axes=None)[source]

Initialize a new instance.

Parameters:
domainDiscretizedSpace

Domain of the wavelet transform (the "image domain").

waveletstring or pywt.Wavelet

Specification of the wavelet to be used in the transform. If a string is given, it is converted to a pywt.Wavelet. Use pywt.wavelist to get a list of available wavelets.

Possible wavelet families are:

'haar': Haar

'db': Daubechies

'sym': Symlets

'coif': Coiflets

'bior': Biorthogonal

'rbio': Reverse biorthogonal

'dmey': Discrete FIR approximation of the Meyer wavelet

nlevelspositive int, optional

Number of scaling levels to be used in the decomposition. The maximum number of levels can be calculated with pywt.dwtn_max_level. Default: Use maximum number of levels.

pad_modestring, optional

Method to be used to extend the signal.

'constant': Fill with pad_const.

'symmetric': Reflect at the boundaries, not repeating the outmost values.

'periodic': Fill in values from the other side, keeping the order.

'order0': Extend constantly with the outmost values (ensures continuity).

'order1': Extend with constant slope (ensures continuity of the first derivative). This requires at least 2 values along each axis where padding is applied.

'pywt_per': like 'periodic'-padding but gives the smallest possible number of decomposition coefficients. Only available with impl='pywt', See pywt.Modes.modes.

'reflect': Reflect at the boundary, without repeating the outmost values.

'antisymmetric': Anti-symmetric variant of symmetric.

'antireflect': Anti-symmetric variant of reflect.

For reference, the following table compares the naming conventions for the modes in ODL vs. PyWavelets:

======================= ==================
          ODL               PyWavelets
======================= ==================
symmetric               symmetric
reflect                 reflect
order1                  smooth
order0                  constant
constant, pad_const=0   zero
periodic                periodic
pywt_per                periodization
antisymmetric           antisymmetric
antireflect             antireflect
======================= ==================

See signal extension modes for an illustration of the modes (under the PyWavelets naming conventions).

pad_constfloat, optional

Constant value to use if pad_mode == 'constant'. Ignored otherwise. Constants other than 0 are not supported by the pywt back-end.

impl{'pywt'}, optional

Backend for the wavelet transform.

axessequence of ints, optional

Axes over which the DWT that created coeffs was performed. The default value of None corresponds to all axes. When not all axes are included this is analagous to a batch transform in len(axes) dimensions looped over the non-transformed axes. In orther words, filtering and decimation does not occur along any axes not in axes.

References

Examples

Compute a very simple wavelet transform in a discrete 2D space with 4 sampling points per axis:

>>> space = odl.uniform_discr([0, 0], [1, 1], (4, 4))
>>> wavelet_trafo = odl.trafos.WaveletTransform(
...     domain=space, nlevels=1, wavelet='haar')
>>> wavelet_trafo.is_biorthogonal
True
>>> data = [[1, 1, 1, 1],
...         [0, 0, 0, 0],
...         [0, 0, 1, 1],
...         [1, 0, 1, 0]]
>>> decomp = wavelet_trafo(data)
>>> decomp.shape
(16,)

It is also possible to apply the transform only along a subset of the axes. Here, we apply a 1D wavelet transfrom along axis 0 for each index along axis 1:

>>> wavelet_trafo = odl.trafos.WaveletTransform(
...     domain=space, nlevels=1, wavelet='haar', axes=(0,))
>>> decomp = wavelet_trafo(data)
>>> decomp.shape
(16,)

In general, the size of the coefficients may exceed the size of the input data when the wavelet is longer than the Haar wavelet. This due to extra coefficients that must be kept for perfect reconstruction. No extra boundary coefficients are needed when the edge mode is "pywt_periodic" and the size along each transformed axis is a multiple of 2**nlevels.

>>> space = odl.uniform_discr([0, 0], [1, 1], (16, 16))
>>> space.size
256
>>> wavelet_trafo = odl.trafos.WaveletTransform(
...     domain=space, nlevels=2, wavelet='db2',
...     pad_mode='pywt_periodic')
>>> decomp = wavelet_trafo(np.ones(space.shape))
>>> decomp.shape
(256,)
>>> wavelet_trafo = odl.trafos.WaveletTransform(
...     domain=space, nlevels=2, wavelet='db2', pad_mode='symmetric')
>>> decomp = wavelet_trafo(np.ones(space.shape))
>>> decomp.shape
(387,)