Rotation¶
-
class
menpo.transform.
Rotation
(rotation_matrix, skip_checks=False)[source]¶ Bases:
DiscreteAffine
,Similarity
Abstract n_dims rotation transform.
Parameters: - rotation_matrix (
(n_dims, n_dims)
ndarray) – A valid, square rotation matrix - skip_checks (bool, optional) – If
True
avoid sanity checks onrotation_matrix
for performance.
-
apply
(x, batch_size=None, **kwargs)¶ Applies this transform to
x
.If
x
isTransformable
,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- x (
-
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
) – TheTransformable
object to be transformed. - kwargs (dict) – Passed through to
_apply()
.
Returns: transformed (
type(x)
) – The transformed object- x (
-
as_vector
(**kwargs)¶ Returns a flattened representation of the object as a single vector.
Returns: vector ((N,) ndarray) – The core representation of the object, flattened into a single vector. Note that this is always a view back on to the original object, but is not writable.
-
axis_and_angle_of_rotation
()[source]¶ Abstract method for computing the axis and angle of rotation.
Returns: - axis (
(n_dims,)
ndarray) – The unit vector representing the axis of rotation - angle_of_rotation (float) – The angle in radians of the rotation about the axis. The angle is signed in a right handed sense.
- axis (
-
compose_after
(transform)¶ A
Transform
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
.An attempt is made to perform native composition, but will fall back to a
TransformChain
as a last resort. Seecomposes_with
for a description of how the mode of composition is decided.Parameters: transform ( Transform
) – Transform to be applied beforeself
Returns: transform ( Transform
orTransformChain
) – If the composition was native, a single newTransform
will be returned. If not, aTransformChain
is returned instead.
-
compose_after_inplace
(transform)¶ Update
self
so that it represents this transform composed after the given transform:a_orig = a.copy() a.compose_after_inplace(b) a.apply(p) == a_orig.apply(b.apply(p))
a
is permanently altered to be the result of the composition.b
is left unchanged.Parameters: transform ( composes_inplace_with
) – Transform to be applied beforeself
Raises: ValueError
– Iftransform
isn’t an instance ofcomposes_inplace_with
-
compose_before
(transform)¶ A
Transform
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.An attempt is made to perform native composition, but will fall back to a
TransformChain
as a last resort. Seecomposes_with
for a description of how the mode of composition is decided.Parameters: transform ( Transform
) – Transform to be applied afterself
Returns: transform ( Transform
orTransformChain
) – If the composition was native, a single newTransform
will be returned. If not, aTransformChain
is returned instead.
-
compose_before_inplace
(transform)¶ Update
self
so that it represents this transform composed before the given transform:a_orig = a.copy() a.compose_before_inplace(b) a.apply(p) == b.apply(a_orig.apply(p))
a
is permanently altered to be the result of the composition.b
is left unchanged.Parameters: transform ( composes_inplace_with
) – Transform to be applied afterself
Raises: ValueError
– Iftransform
isn’t an instance ofcomposes_inplace_with
-
copy
()¶ Generate an efficient copy of this object.
Note that Numpy arrays and other
Copyable
objects onself
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
-
decompose
()¶ A
DiscreteAffine
is already maximally decomposed - return a copy of self in a list.Returns: transform ( DiscreteAffine
) – Deep copy of self.
-
from_vector
(vector)¶ Build a new instance of the object from its vectorized state.
self
is used to fill out the missing state required to rebuild a full object from it’s standardized flattened state. This is the default implementation, which is adeepcopy
of the object followed by a call tofrom_vector_inplace()
. This method can be overridden for a performance benefit if desired.Parameters: vector ( (n_parameters,)
ndarray) – Flattened representation of the object.Returns: transform ( Homogeneous
) – An new instance of this class.
-
from_vector_inplace
(p)[source]¶ Returns an instance of the transform from the given parameters, expected to be in Fortran ordering.
Supports rebuilding from 2D parameter sets.
2D Rotation: 1 parameter:
[theta]
Parameters: p ( (1,)
ndarray) – The array of parameters.Returns: transform ( Rotation
) – The transform initialised to the given parameters.
-
has_nan_values
()¶ Tests if the vectorized form of the object contains
nan
values or not. This is particularly useful for objects with unknown values that have been mapped tonan
values.Returns: has_nan_values (bool) – If the vectorized object contains nan
values.
-
classmethod
init_from_2d_ccw_angle
(theta, degrees=True)[source]¶ Convenience constructor for 2D CCW rotations about the origin.
Parameters: - theta (float) – The angle of rotation about the origin
- degrees (bool, optional) – If
True
theta is interpreted as a degree. IfFalse
, theta is interpreted as radians.
Returns: rotation (
Rotation
) – A 2D rotation transform.
-
classmethod
init_identity
(n_dims)[source]¶ Creates an identity transform.
Parameters: n_dims (int) – The number of dimensions. Returns: identity ( Rotation
) – The identity matrix transform.
-
pseudoinverse_vector
(vector)¶ The vectorized pseudoinverse of a provided vector instance. Syntactic sugar for:
self.from_vector(vector).pseudoinverse().as_vector()
Can be much faster than the explict call as object creation can be entirely avoided in some cases.
Parameters: vector ( (n_parameters,)
ndarray) – A vectorized version ofself
Returns: pseudoinverse_vector ( (n_parameters,)
ndarray) – The pseudoinverse of the vector provided
-
set_h_matrix
(value, copy=True, skip_checks=False)¶ Updates
h_matrix
, optionally performing sanity checks.Note that it won’t always be possible to manually specify the
h_matrix
through this method, specifically if changing theh_matrix
could change the nature of the transform. Seeh_matrix_is_mutable
for how you can discover if theh_matrix
is allowed to be set for a given class.Parameters: - value (ndarray) – The new homogeneous matrix to set.
- copy (bool, optional) – If
False
, do not copy the h_matrix. Useful for performance. - skip_checks (bool, optional) – If
True
, skip checking. Useful for performance.
Raises: NotImplementedError
– Ifh_matrix_is_mutable
returnsFalse
.
-
set_rotation_matrix
(value, skip_checks=False)[source]¶ Sets the rotation matrix.
Parameters: - value (
(n_dims, n_dims)
ndarray) – The new rotation matrix. - skip_checks (bool, optional) – If
True
avoid sanity checks onvalue
for performance.
- value (
-
composes_with
¶ Any Homogeneous can compose with any other Homogeneous.
-
h_matrix
¶ The homogeneous matrix defining this transform.
Type: (n_dims + 1, n_dims + 1)
ndarray
-
h_matrix_is_mutable
¶ h_matrix
is not mutable.Type: False
-
has_true_inverse
¶ The pseudoinverse is an exact inverse.
Type: True
-
linear_component
¶ The linear component of this affine transform.
Type: (n_dims, n_dims)
ndarray
-
n_dims
¶ The dimensionality of the data the transform operates on.
Type: int
-
n_dims_output
¶ The output of the data from the transform.
Type: int
-
rotation_matrix
¶ The rotation matrix.
Type: (n_dims, n_dims)
ndarray
-
translation_component
¶ The translation component of this affine transform.
Type: (n_dims,)
ndarray
- rotation_matrix (