ThinPlateSplines

class menpo.transform.ThinPlateSplines(source, target, kernel=None, min_singular_val=0.0001)[source]

Bases: Alignment, Transform, Invertible

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 R2LogR2RBF 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 (RadialBasisFunction, optional) – The kernel to apply.
  • min_singular_val (float, optional) – If the target has points that are nearly coincident, the coefficients matrix is rank deficient, and therefore not invertible. Therefore, we only take the inverse on the full-rank matrix and drop any singular values that are less than this value (close to zero).
Raises:

ValueError – TPS is only with on 2-dimensional data

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
apply(x, batch_size=None, **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.
  • batch_size (int, optional) – If not None, this determines how many items from the numpy array will be passed through the transform at a time. This is useful for operations that require large intermediate matrices to be computed.
  • 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.
copy()

Generate an efficient copy of this object.

Note that Numpy arrays and other Copyable objects on self will be deeply copied. Dictionaries and sets will be shallow copied, and everything else will be assigned (no copy will be made).

Classes that store state other than numpy arrays and immutable types should overwrite this method to ensure all state is copied.

Returns:type(self) – A copy of this object
pseudoinverse()[source]

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)
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.
has_true_inverse
Type:False
n_dims

The number of dimensions of the target.

Type:int
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
n_points

The number of points on the target.

Type:int
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