kornia.geometry.linalg

kornia.geometry.linalg.relative_transformation(trans_01, trans_02)[source]

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)[source]

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 \((B, 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 \((B, 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)[source]

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 – transformation tensor of shape \((N, 4, 4)\) or \((4, 4)\).

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)[source]

Function that applies transformations to a set of points.

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

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

Returns

tensor of N-dimensional points.

Return type

torch.Tensor

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.perspective_transform_lafs(trans_01, lafs_1)[source]

Function that applies perspective transformations to a set of local affine frames (LAFs).

Parameters
  • trans_01 (Tensor) – tensor for perspective transformations of shape \((B, 3, 3)\).

  • lafs_1 (Tensor) – tensor of lafs of shape \((B, N, 2, 3)\).

Return type

Tensor

Returns

tensor of N-dimensional points of shape \((B, N, 2, 3)\).

Examples

>>> rng = torch.manual_seed(0)
>>> lafs_1 = torch.rand(2, 4, 2, 3)  # BxNx2x3
>>> lafs_1
tensor([[[[0.4963, 0.7682, 0.0885],
          [0.1320, 0.3074, 0.6341]],

         [[0.4901, 0.8964, 0.4556],
          [0.6323, 0.3489, 0.4017]],

         [[0.0223, 0.1689, 0.2939],
          [0.5185, 0.6977, 0.8000]],

         [[0.1610, 0.2823, 0.6816],
          [0.9152, 0.3971, 0.8742]]],


        [[[0.4194, 0.5529, 0.9527],
          [0.0362, 0.1852, 0.3734]],

         [[0.3051, 0.9320, 0.1759],
          [0.2698, 0.1507, 0.0317]],

         [[0.2081, 0.9298, 0.7231],
          [0.7423, 0.5263, 0.2437]],

         [[0.5846, 0.0332, 0.1387],
          [0.2422, 0.8155, 0.7932]]]])
>>> trans_01 = torch.eye(3).repeat(2, 1, 1)  # Bx3x3
>>> trans_01.shape
torch.Size([2, 3, 3])
>>> lafs_0 = perspective_transform_lafs(trans_01, lafs_1)  # BxNx2x3