kornia.geometry.linalg

kornia.geometry.linalg.relative_transformation(trans_01, trans_02)

Function that computes the relative homogeneous transformation from a reference transformation.

\(T_1^{0} = \begin{bmatrix} R_1 & t_1 \\ \mathbf{0} & 1 \end{bmatrix}\) to destination \(T_2^{0} = \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}\]
Parameters:
  • trans_01 (Tensor) – reference transformation tensor of shape \((N, 4, 4)\) or \((4, 4)\).

  • trans_02 (Tensor) – destination transformation tensor of shape \((N, 4, 4)\) or \((4, 4)\).

Return type:

Tensor

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)

Function that composes 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}\]
Parameters:
  • trans_01 (Tensor) – tensor with the homogeneous transformation from a reference frame 1 respect to a frame 0. The tensor has 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 has must have a shape of \((N, 4, 4)\) or \((4, 4)\).

Return type:

Tensor

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)

Function that inverts a 4x4 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}\]
Parameters:

trans_12 (Tensor) – transformation tensor of shape \((N, 4, 4)\) or \((4, 4)\).

Return type:

Tensor

Returns:

tensor with inverted transformations with shape \((N, 4, 4)\) or \((4, 4)\).

Example

>>> trans_12 = torch.rand(1, 4, 4)  # Nx4x4
>>> trans_21 = inverse_transformation(trans_12)  # Nx4x4
kornia.geometry.linalg.transform_points(trans_01, points_1)

Function that applies transformations to a set of points.

Parameters:
  • trans_01 (Tensor) – tensor for transformations of shape \((B, D+1, D+1)\).

  • points_1 (Tensor) – tensor of points of shape \((B, N, D)\).

Return type:

Tensor

Returns:

a tensor of N-dimensional points.

Shape:
  • Output: \((B, N, D)\)

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)

Return the distance from points to lines.

Parameters:
  • point (Tensor) – (possibly homogeneous) points \((*, N, 2 or 3)\).

  • line (Tensor) – lines coefficients \((a, b, c)\) with shape \((*, N, 3)\), where \(ax + by + c = 0\).

  • eps (float, optional) – Small constant for safe sqrt. Default: 1e-9

Return type:

Tensor

Returns:

the computed distance with shape \((*, N)\).

kornia.geometry.linalg.squared_norm(x, keepdim=False)

Return the squared norm of a vector.

Return type:

Tensor

kornia.geometry.linalg.batched_dot_product(x, y, keepdim=False)

Return a batched version of .dot()

Return type:

Tensor

kornia.geometry.linalg.euclidean_distance(x, y, keepdim=False, eps=1e-6)

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: False

  • eps (float, optional) – small value to have numerical stability. Default: 1e-6

Return type:

Tensor