kornia.geometry.linalg#
- kornia.geometry.linalg.relative_transformation(trans_01, trans_02)[source]#
Compute the relative homogeneous transformation from a reference transformation.
Given the reference \(T_0^{1} = \begin{bmatrix} R_1 & t_1 \\ \mathbf{0} & 1 \end{bmatrix}\) and the destination \(T_0^{2} = \begin{bmatrix} R_2 & t_2 \\ \mathbf{0} & 1 \end{bmatrix}\), the relative transformation is computed as follows:
\[T_1^{2} = (T_0^{1})^{-1} \cdot T_0^{2}\]- Convention:
trans_ab(\(T_a^{b}\)) maps points in framebto framea, \(p_a = T_a^{b} p_b\):transform_points(trans_01, points_1)returnspoints_0, andcompose_transformations(trans_01, trans_12)returnstrans_02. Rotations and rigid motions maps this onto other libraries.trans_01must be a rigid \([R|t]\), as forinverse_transformation(), and the last row oftrans_02is read as \([0, 0, 0, 1]\), as incompose_transformations(). Neither is validated: a scaled, sheared or projectivetrans_01, or a projectivetrans_02, gives a wrong result silently.relative_camera_motion()takes world-to-camera extrinsics \(E_1, E_2\) and returns the \([R|t]\) of \(E_2 E_1^{-1}\), which isrelative_transformationof \(E_2^{-1}\) and \(E_1^{-1}\), in this order, not of \(E_1\) and \(E_2\).
- Parameters:
- Return type:
- Returns:
the relative transformation between the transformations with shape \((N, 4, 4)\) or \((4, 4)\).
- Example::
>>> trans_01 = torch.eye(4) # 4x4 >>> trans_02 = torch.eye(4) # 4x4 >>> trans_12 = relative_transformation(trans_01, trans_02) # 4x4
- kornia.geometry.linalg.compose_transformations(trans_01, trans_12)[source]#
Compose two homogeneous transformations.
\[\begin{split}T_0^{2} = \begin{bmatrix} R_0^{1} R_1^{2} & R_0^{1} t_1^{2} + t_0^{1} \\ \mathbf{0} & 1 \end{bmatrix}\end{split}\]- Convention:
The result is the matrix product
trans_01 @ trans_12, with the frame naming ofrelative_transformation(). Only the top three rows of each input are read and the last row of the result is always \([0, 0, 0, 1]\): any affine pair composes exactly, and a projective input is used as if its last row were \([0, 0, 0, 1]\).
- Parameters:
trans_01 (
Tensor) – tensor with the homogeneous transformation from a reference frame 1 respect to a frame 0. The tensor must have a shape of \((N, 4, 4)\) or \((4, 4)\).trans_12 (
Tensor) – tensor with the homogeneous transformation from a reference frame 2 respect to a frame 1. The tensor must have a shape of \((N, 4, 4)\) or \((4, 4)\). A batch of one broadcasts against a batch of \(N\) in either argument.
- Return type:
- Returns:
the transformation between the two frames with shape \((N, 4, 4)\) or \((4, 4)\).
- Example::
>>> trans_01 = torch.eye(4) # 4x4 >>> trans_12 = torch.eye(4) # 4x4 >>> trans_02 = compose_transformations(trans_01, trans_12) # 4x4
- kornia.geometry.linalg.inverse_transformation(trans_12)[source]#
Invert a 4x4 rigid homogeneous transformation.
\(T_1^{2} = \begin{bmatrix} R_1 & t_1 \\ \mathbf{0} & 1 \end{bmatrix}\)
The inverse transformation is computed as follows:
\[\begin{split}T_2^{1} = (T_1^{2})^{-1} = \begin{bmatrix} R_1^T & -R_1^T t_1 \\ \mathbf{0} & 1\end{bmatrix}\end{split}\]- Convention:
The input must be a rigid \([R|t]\), and this is not validated: the rotation block is transposed, not inverted, and the last row is read as \([0, 0, 0, 1]\), so a scaled, sheared or projective matrix returns a result that is not its inverse. Use
torch.linalg.inv()for a general matrix. Frame naming is onrelative_transformation().
- Parameters:
trans_12 (
Tensor) – transformation tensor of shape \((N, 4, 4)\) or \((4, 4)\).- Return type:
- Returns:
tensor with inverted transformations with shape \((N, 4, 4)\) or \((4, 4)\).
Example
>>> trans_12 = torch.eye(4)[None] # Nx4x4: a rotation of 90 degrees about z and a translation >>> trans_12[:, :3, :3] = torch.tensor([[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]) >>> trans_12[:, :3, 3] = torch.tensor([1.0, 2.0, 3.0]) >>> trans_21 = inverse_transformation(trans_12) # Nx4x4 >>> trans_21[:, :3, 3] tensor([[-2., 1., -3.]])
- kornia.geometry.linalg.transform_points(trans_01, points_1)[source]#
Apply transformations to a set of points.
- Parameters:
- Return type:
- Returns:
transformed points with the same shape as
points_1.
- Shape:
Output: same shape as
points_1.
Examples
>>> points_1 = torch.rand(2, 4, 3) # BxNx3 >>> trans_01 = torch.eye(4).view(1, 4, 4) # Bx4x4 >>> points_0 = transform_points(trans_01, points_1) # BxNx3
- kornia.geometry.linalg.point_line_distance(point, line, eps=1e-9)[source]#
Return the distance from points to lines.
- Convention:
lineneed not be normalised: the distance is \(|ax + by + c| / \|(a, b)\|\) at every scale of the coefficients. A line with \(a = b = 0\), the line at infinity or no line at all, is at distanceinffrom every point, as a point at infinity is from every line.
- Parameters:
point (
Tensor) – points \((*, N, 2)\), or homogeneous points \((*, N, 3)\) whose last coordinate is the weight \(w\); a point at infinity (\(w = 0\)) is at distanceinffrom every line.line (
Tensor) – lines coefficients \((a, b, c)\) with shape \((*, N, 3)\), where \(ax + by + c = 0\).eps (
float, optional) – unused; it was added to \(\|(a, b)\|\) and made the distance depend on the scale of the line (#4881). The singular line is guarded exactly instead. Accepted so that existing calls keep working. Default:1e-9
- Return type:
- Returns:
the computed distance with shape \((*, N)\).
- kornia.geometry.linalg.batched_squared_norm(x, keepdim=False)[source]#
Return the squared norm of a vector.
- Return type:
- kornia.geometry.linalg.squared_norm(x, keepdim=False)[source]#
Return the squared norm of a vector.
- Return type:
- kornia.geometry.linalg.batched_dot_product(x, y, keepdim=False)[source]#
Return a batched version of .dot().
- Return type:
- kornia.geometry.linalg.euclidean_distance(x, y, keepdim=False, eps=1e-6)[source]#
Compute the Euclidean distance between two set of n-dimensional points.
More: https://en.wikipedia.org/wiki/Euclidean_distance
- Parameters:
x (
Tensor) – first set of points of shape \((*, N)\).y (
Tensor) – second set of points of shape \((*, N)\).keepdim (
bool, optional) – whether to keep the dimension after reduction. Default:Falseeps (
float, optional) – unused; kept for backward compatibility. The result is the exact Euclidean distance. Default:1e-6
- Return type: