Abstract representation of any spatial transform.
All Transforms support basic composition to form a
There are two useful forms of composition. Firstly, the mathematical composition symbol o has the following definition:
Let a(x) and b(x) be two transforms on x. (a o b)(x) == a(b(x))
This functionality is provided by the
compose_after()family of methods:
(a.compose_after(b)).apply(x) == a.apply(b.apply(x))
Equally useful is an inversion the order of composition - so that over time a large chain of transforms can be built to do a useful job, and composing on this chain adds another transform to the end (after all other preceding transforms have been performed).
For instance, let’s say we want to rescale a
paround its mean, and then translate it some place else. It would be nice to be able to do something like:
t = Translation(-p.centre) # translate to centre s = Scale(2.0) # rescale move = Translate([10, 0 ,0]) # budge along the x axis t.compose(s).compose(-t).compose(move)
In Menpo, this functionality is provided by the
compose_before()family of methods:
(a.compose_before(b)).apply(x) == b.apply(a.apply(x))
For native composition, see the
ComposableTransformsubclass and the
For alignment, see the
apply(x, batch_size=None, **kwargs)¶
Applies this transform to
xwill be handed this transform object to transform itself non-destructively (a transformed copy of the object will be returned).
xis assumed to be an ndarray. The transformation will be non-destructive, returning the transformed version.
kwargswill be passed to the specific transform
(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
type(x)) – The transformed object or array
Deprecated as public supported API, use the non-mutating apply() instead.
For internal performance-specific uses, see _apply_inplace().
TransformChainthat represents this transform composed after the given transform:
c = a.compose_after(b) c.apply(p) == a.apply(b.apply(p))
bare left unchanged.
This corresponds to the usual mathematical formalism for the compose operator, o.
TransformChainthat represents this transform composed before the given transform:
c = a.compose_before(b) c.apply(p) == b.apply(a.apply(p))
bare left unchanged.
Generate an efficient copy of this object.
Note that Numpy arrays and other
selfwill 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.
type(self)– A copy of this object
The dimensionality of the data the transform operates on.
Noneif the transform is not dimension specific.
The output of the data from the transform.
Noneif the output of the transform is not dimension specific.