linear_deform

odl.deform.linearized.linear_deform(template, displacement, interp='linear', out=None)[source]

Linearized deformation of a template with a displacement field.

The function maps a given template I and a given displacement field v to the new function x --> I(x + v(x)).

Parameters
templateDiscretizedSpaceElement

Template to be deformed by a displacement field.

displacementelement of power space of template.space

Vector field (displacement field) used to deform the template.

interpstr or sequence of str

Interpolation type that should be used to sample the template on the deformed grid. A single value applies to all axes, and a sequence gives the interpolation scheme per axis.

Supported values: 'nearest', 'linear'

outnumpy.ndarray, optional

Array to which the function values of the deformed template are written. It must have the same shape as template and a data type compatible with template.dtype.

Returns
deformed_templatenumpy.ndarray

Function values of the deformed template. If out was given, the returned object is a reference to it.

Examples

Create a simple 1D template to initialize the operator and apply it to a displacement field. Where the displacement is zero, the output value is the same as the input value. In the 4-th point, the value is taken from 0.2 (one cell) to the left, i.e. 1.0.

>>> space = odl.uniform_discr(0, 1, 5)
>>> disp_field_space = space.tangent_bundle
>>> template = space.element([0, 0, 1, 0, 0])
>>> displacement_field = disp_field_space.element([[0, 0, 0, -0.2, 0]])
>>> linear_deform(template, displacement_field, interp='nearest')
array([ 0.,  0.,  1.,  1.,  0.])

The result depends on the chosen interpolation. With ‘linear’ interpolation and an offset of half the distance between two points, 0.1, one gets the mean of the values.

>>> displacement_field = disp_field_space.element([[0, 0, 0, -0.1, 0]])
>>> linear_deform(template, displacement_field, interp='linear')
array([ 0. ,  0. ,  1. ,  0.5,  0. ])