DifferentiableThinPlateSplines¶
-
class
menpofit.transform.
DifferentiableThinPlateSplines
(source, target, kernel=None)[source]¶ Bases:
ThinPlateSplines
,DL
,DX
The Thin Plate Splines (TPS) alignment between 2D source and target landmarks. The transform can compute its own derivative with respect to spatial changes, as well as anchor landmark changes.
- Parameters
source (
(N, 2)
ndarray) – The source points to apply the tps fromtarget (
(N, 2)
ndarray) – The target points to apply the tps tokernel (class or
None
, optional) – The differentiable kernel to apply. Possible options areDifferentiableR2LogRRBF
andDifferentiableR2LogR2RBF
. IfNone
, thenDifferentiableR2LogR2RBF
is used.
-
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
(*args, **kwargs)¶ Deprecated as public supported API, use the non-mutating apply() instead.
For internal performance-specific uses, see _apply_inplace().
-
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
andb
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
andb
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
-
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)
ndarray) – The spatial points at which the derivative should 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 (
(n_points, n_dims)
ndarray) – The spatial points at which the derivative should be evaluated.- Returns
d_dx (
(n_points, n_dims, n_dims)
ndarray) – The Jacobian wrt spatial changes.d_dx[i, j, k]
is the scalar differential change that thej
’th dimension of thei
’th point experiences due to a first order change in thek
’th dimension.It may be the case that the Jacobian is constant across space - in this case axis zero may have length
1
to allow for broadcasting.
-
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)
-
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.
-
property
has_true_inverse
¶ False
- Type
type
-
property
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
-
property
source
¶ The source PointCloud that is used in the alignment.
The source is not mutable.
- Type
-
property
target
¶ The current PointCloud that this object produces.
To change the target, use
set_target()
.- Type