kornia.geometry.conversions

rad2deg(tensor: torch.Tensor) → torch.Tensor[source]

Function that converts angles from radians to degrees.

Parameters:tensor (torch.Tensor) – Tensor of arbitrary shape.
Returns:Tensor with same shape as input.
Return type:torch.Tensor

Example

>>> input = kornia.pi * torch.rand(1, 3, 3)
>>> output = kornia.rad2deg(input)
deg2rad(tensor: torch.Tensor) → torch.Tensor[source]

Function that converts angles from degrees to radians.

Parameters:tensor (torch.Tensor) – Tensor of arbitrary shape.
Returns:tensor with same shape as input.
Return type:torch.Tensor

Examples:

>>> input = 360. * torch.rand(1, 3, 3)
>>> output = kornia.deg2rad(input)
convert_points_from_homogeneous(points: torch.Tensor) → torch.Tensor[source]

Function that converts points from homogeneous to Euclidean space.

Examples:

>>> input = torch.rand(2, 4, 3)  # BxNx3
>>> output = kornia.convert_points_from_homogeneous(input)  # BxNx2
convert_points_to_homogeneous(points: torch.Tensor) → torch.Tensor[source]

Function that converts points from Euclidean to homogeneous space.

Examples:

>>> input = torch.rand(2, 4, 3)  # BxNx3
>>> output = kornia.convert_points_to_homogeneous(input)  # BxNx4
angle_axis_to_rotation_matrix(angle_axis: torch.Tensor) → torch.Tensor[source]

Convert 3d vector of axis-angle rotation to 4x4 rotation matrix

Parameters:angle_axis (torch.Tensor) – tensor of 3d vector of axis-angle rotations.
Returns:tensor of 4x4 rotation matrices.
Return type:torch.Tensor
Shape:
  • Input: \((N, 3)\)
  • Output: \((N, 4, 4)\)

Example

>>> input = torch.rand(1, 3)  # Nx3
>>> output = kornia.angle_axis_to_rotation_matrix(input)  # Nx4x4
rotation_matrix_to_angle_axis(rotation_matrix: torch.Tensor) → torch.Tensor[source]

Convert 3x4 rotation matrix to Rodrigues vector

Parameters:rotation_matrix (torch.Tensor) – rotation matrix.
Returns:Rodrigues vector transformation.
Return type:torch.Tensor
Shape:
  • Input: \((N, 3, 4)\)
  • Output: \((N, 3)\)

Example

>>> input = torch.rand(2, 3, 4)  # Nx4x4
>>> output = kornia.rotation_matrix_to_angle_axis(input)  # Nx3
rotation_matrix_to_quaternion(rotation_matrix: torch.Tensor) → torch.Tensor[source]

Convert 3x4 rotation matrix to 4d quaternion vector

This algorithm is based on algorithm described in https://github.com/KieranWynn/pyquaternion/blob/master/pyquaternion/quaternion.py#L201

Parameters:rotation_matrix (torch.Tensor) – the rotation matrix to convert.
Returns:the rotation in quaternion.
Return type:torch.Tensor
Shape:
  • Input: \((N, 3, 4)\)
  • Output: \((N, 4)\)

Example

>>> input = torch.rand(4, 3, 4)  # Nx3x4
>>> output = kornia.rotation_matrix_to_quaternion(input)  # Nx4
quaternion_to_angle_axis(quaternion: torch.Tensor) → torch.Tensor[source]

Convert quaternion vector to angle axis of rotation.

Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h

Parameters:quaternion (torch.Tensor) – tensor with quaternions.
Returns:tensor with angle axis of rotation.
Return type:torch.Tensor
Shape:
  • Input: \((*, 4)\) where * means, any number of dimensions
  • Output: \((*, 3)\)

Example

>>> quaternion = torch.rand(2, 4)  # Nx4
>>> angle_axis = kornia.quaternion_to_angle_axis(quaternion)  # Nx3
angle_axis_to_quaternion(angle_axis: torch.Tensor) → torch.Tensor[source]

Convert an angle axis to a quaternion.

Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h

Parameters:angle_axis (torch.Tensor) – tensor with angle axis.
Returns:tensor with quaternion.
Return type:torch.Tensor
Shape:
  • Input: \((*, 3)\) where * means, any number of dimensions
  • Output: \((*, 4)\)

Example

>>> angle_axis = torch.rand(2, 4)  # Nx4
>>> quaternion = kornia.angle_axis_to_quaternion(angle_axis)  # Nx3
rtvec_to_pose(rtvec: torch.Tensor) → torch.Tensor[source]

Convert axis-angle rotation and translation vector to 4x4 pose matrix

Parameters:rtvec (torch.Tensor) – Rodrigues vector transformations
Returns:transformation matrices
Return type:torch.Tensor
Shape:
  • Input: \((N, 6)\)
  • Output: \((N, 4, 4)\)

Example

>>> input = torch.rand(3, 6)  # Nx6
>>> output = kornia.rtvec_to_pose(input)  # Nx4x4
normalize_pixel_coordinates(pixel_coordinates: torch.Tensor, height: int, width: int) → torch.Tensor[source]

Normalize pixel coordinates between -1 and 1.

Normalized, -1 if on extreme left, 1 if on extreme right (x = w-1).

Parameters:
  • pixel_coordinate (torch.Tensor) – the grid with pixel coordinates. Shape must be \((B, H, W, 2)\).
  • width (int) – the maximum width in the x-axis.
  • height (int) – the maximum height in the y-axis.
Returns:

the nornmalized pixel coordinates.

Return type:

torch.Tensor