# kornia.geometry.linalg¶

relative_transformation(trans_01: torch.Tensor, trans_02: torch.Tensor) → torch.Tensor[source]

Function that computes the relative homogenous 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 (torch.Tensor) – reference transformation tensor of shape $$(N, 4, 4)$$ or $$(4, 4)$$.

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

Shape:
• Output: $$(N, 4, 4)$$ or $$(4, 4)$$.

Returns

the relative transformation between the transformations.

Return type

torch.Tensor

Example::
>>> trans_01 = torch.eye(4)  # 4x4
>>> trans_02 = torch.eye(4)  # 4x4
>>> trans_12 = kornia.relative_transformation(trans_01, trans_02)  # 4x4

compose_transformations(trans_01: torch.Tensor, trans_12: torch.Tensor) → torch.Tensor[source]

Functions 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 (torch.Tensor) – tensor with the homogenous 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 (torch.Tensor) – tensor with the homogenous 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)$$.

Shape:
• Output: $$(N, 4, 4)$$ or $$(4, 4)$$

Returns

the transformation between the two frames.

Return type

torch.Tensor

Example::
>>> trans_01 = torch.eye(4)  # 4x4
>>> trans_12 = torch.eye(4)  # 4x4
>>> trans_02 = kornia.compose_transformations(trans_01, trans_12)  # 4x4

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

Returns

tensor with inverted transformations.

Return type

torch.Tensor

Shape:
• Output: $$(N, 4, 4)$$ or $$(4, 4)$$

Example

>>> trans_12 = torch.rand(1, 4, 4)  # Nx4x4
>>> trans_21 = kornia.inverse_transformation(trans_12)  # Nx4x4

transform_points(trans_01: torch.Tensor, points_1: torch.Tensor) → torch.Tensor[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 = kornia.transform_points(trans_01, points_1)  # BxNx3

transform_boxes(trans_mat: torch.Tensor, boxes: torch.Tensor, mode: str = 'xyxy') → torch.Tensor[source]

Function that applies a transformation matrix to a box or batch of boxes. Boxes must be a tensor of the shape (N, 4) or a batch of boxes (B, N, 4) and trans_mat must be a (3, 3) transformation matrix or a batch of transformation matrices (B, 3, 3)

Parameters
• trans_mat (torch.Tensor) – The transformation matrix to be applied

• boxes (torch.Tensor) – The boxes to be transformed

• mode (str) – The format in which the boxes are provided. If set to ‘xyxy’ the boxes are assumed to be in the format (xmin, ymin, xmax, ymax). If set to ‘xywh’ the boxes are assumed to be in the format (xmin, ymin, width, height). Default: ‘xyxy’

Returns

The set of transformed points in the specified mode

Return type

torch.Tensor

perspective_transform_lafs(trans_01: torch.Tensor, lafs_1: torch.Tensor) → torch.Tensor[source]

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

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

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

Returns

tensor of N-dimensional points.

Return type

torch.Tensor

Shape:
• Output: $$(B, N, 2, 3)$$

Examples

>>> lafs_1 = torch.rand(2, 4, 2, 3)  # BxNx2x3
>>> trans_01 = torch.eye(3).view(1, 3, 3)  # Bx3x3
>>> lafs_0 = kornia.perspective_transform_lafs(trans_01, lafs_1)  # BxNx2x3