ThinPlateSplines¶
- class menpo.transform.thinplatesplines.ThinPlateSplines(source, target, kernel=None)[source]¶
Bases: Alignment, Transform, Invertible, DX, DL
The thin plate splines (TPS) alignment between 2D source and target landmarks.
kernel can be used to specify an alternative kernel function. If None is supplied, the R2LogR2 kernel will be used.
Parameters: source : (N, 2) ndarray
The source points to apply the tps from
target : (N, 2) ndarray
The target points to apply the tps to
kernel : BasisFunction, optional
The kernel to apply.
Default: R2LogR2
Raises: ValueError :
TPS is only with on 2-dimensional data
- apply(x, **kwargs)¶
Applies this transform to x.
If x is Transformable, x will be handed this transform object to transform itself non-destructively (a transformed copy of the object will be returned).
If not, x is assumed to be an ndarray. The transformation will be non-destructive, returning the transformed version.
Any kwargs will be passed to the specific transform _apply() method.
Parameters: x : Transformable or (n_points, n_dims) ndarray
The array or object to be transformed.
kwargs : dict
Passed through to _apply().
Returns: transformed : type(x)
The transformed object or array
- apply_inplace(x, **kwargs)¶
Applies this transform to a Transformable x destructively.
Any kwargs will be passed to the specific transform _apply() method.
Parameters: x : Transformable
The Transformable object to be transformed.
kwargs : dict
Passed through to _apply().
Returns: transformed : type(x)
The transformed object
- compose_after(transform)¶
Returns a TransformChain that represents this transform composed after the given transform:
c = a.compose_after(b) c.apply(p) == a.apply(b.apply(p))
a and b are left unchanged.
This corresponds to the usual mathematical formalism for the compose operator, o.
Parameters: transform : Transform
Transform to be applied before self
Returns: transform : TransformChain
The resulting transform chain.
- compose_before(transform)¶
Returns a TransformChain that represents this transform composed before the given transform:
c = a.compose_before(b) c.apply(p) == b.apply(a.apply(p))
a and b are left unchanged.
Parameters: transform : Transform
Transform to be applied after self
Returns: transform : TransformChain
The resulting transform chain.
- d_dl(points)[source]¶
Calculates the Jacobian of the TPS warp wrt to the source landmarks assuming that he target is equal to the source. This is a special case of the Jacobian wrt to the source landmarks that is used in AAMs to weight the relative importance of each pixel in the reference frame wrt to each one of the source landmarks.
- dW_dl = dOmega_dl * k(points)
- = T * d_L**-1_dl * k(points) = T * -L**-1 dL_dl L**-1 * k(points)
# per point (c, d) = (d, c+3) (c+3, c+3) (c+3, c+3, c, d) (c+3, c+3) (c+3) (c, d) = (d, c+3) (c+3, c+3, c, d) (c+3,) (c, d) = (d, ) ( c, d) (c, d) = ( ) ( c, d)
Parameters: points : (n_points, n_dims)
Points at which the Jacobian will be evaluated.
Returns: dW/dl : (n_points, n_params, n_dims) ndarray
The Jacobian of the transform wrt to the source landmarks evaluated at the previous points and assuming that the target is equal to the source.
- d_dx(points)[source]¶
The first order derivative of this TPS warp wrt spatial changes evaluated at points.
Parameters: points: ndarray shape (n_points, n_dims) :
The spatial points at which the derivative should be evaluated.
Returns: d_dx: ndarray shape (n_points, n_dims, n_dims) :
The jacobian wrt spatial changes.
d_dx[i, j, k] is the scalar differential change that the j’th dimension of the i’th point experiences due to a first order change in the k’th dimension.
- set_target(new_target)¶
Update this object so that it attempts to recreate the new_target.
Parameters: new_target : PointCloud
The new target that this object should try and regenerate.
- view(**kwargs)¶
View the object using the default rendering engine figure handling. For example, the default behaviour for Matplotlib is that all draw commands are applied to the same figure object.
Parameters: kwargs : dict
Passed through to specific rendering engine.
Returns: viewer : Renderer
The renderer instantiated.
- view_new(**kwargs)¶
View the object on a new figure.
Parameters: kwargs : dict
Passed through to specific rendering engine.
Returns: viewer : Renderer
The renderer instantiated.
- view_on(figure_id, **kwargs)¶
View the object on a a specific figure specified by the given id.
Parameters: figure_id : object
A unique identifier for a figure.
kwargs : dict
Passed through to specific rendering engine.
Returns: viewer : Renderer
The renderer instantiated.
- aligned_source¶
The result of applying self to source
Type: PointCloud
- alignment_error¶
The Frobenius Norm of the difference between the target and the aligned source.
Type: float
- n_dims_output¶
The output of the data from the transform.
None if the output of the transform is not dimension specific.
Type: int or None
- pseudoinverse¶
The pseudoinverse of the transform - that is, the transform that results from swapping source and target, or more formally, negating the transforms parameters. If the transform has a true inverse this is returned instead.
Type: type(self)
- source¶
The source PointCloud that is used in the alignment.
The source is not mutable.
Type: PointCloud
- target¶
The current PointCloud that this object produces.
To change the target, use set_target().
Type: PointCloud