kornia.geometry#

Geometric image transformations are another key ingredient in computer vision for manipulating images. Since geometry operations are typically performed in 2D or 3D, we provide algorithms for both cases. This module, the original core of the library, groups its submodules by task:

  • Warp, resize, crop, flip or register images, and build the matrices of those warps: transform.

  • Convert between homogeneous and Euclidean points, pixel and normalized coordinates, rotation forms and pose conventions: conversions.

  • Apply a homogeneous transformation to points, compose, invert or relate 4 x 4 transformations, and measure distances of points to points and lines: linalg. Grids of pixel coordinates: grid.

  • Camera models, the projection and unprojection of points, and the Kannala-Brandt fisheye and affine distortion models on normalized points: camera; OpenCV (Brown-Conrady) lens distortion and undistortion of pixels and images, and pose from 2D-3D correspondences: calibration.

  • 3D points and surface normals from depth maps, and images warped by depth: depth.

  • Two-view geometry, fundamental and essential matrices, relative pose and triangulation: epipolar; homographies from points or line segments: homography; any of these models robust to outliers: ransac; the affine, null-vector and polynomial solvers they build on: solvers.

  • Rotations and rigid motions as objects that compose and invert: liegroup, quaternion, and poses between named frames, pose.

  • Geometric primitives: 2D and 3D boxes, boxes, with the tensor functions of bbox; keypoints; lines and planes, line; 2D and 3D vectors, vector.

  • Sub-pixel peaks, soft argmax and non-maxima suppression of response maps: subpix.

  • Point clouds to and from PLY files: pointcloud.

kornia.geometry re-exports the names of every submodule here except boxes, keypoints and vector (import those from their modules, such as kornia.geometry.boxes.Boxes), and of quaternion only Quaternion.

About align_corners

align_corners is a switch offered by most PyTorch and Kornia geometric transform functions. Here is a simple illustration showing how a 4x4 image is upsampled to 8x8, made by bkkm16.

Illustration of align_corners=True versus align_corners=False when upsampling a 4x4 image to 8x8
  • align_corners=True: pixels are arranged as a grid of points. Points at the corners are aligned.

  • align_corners=False: pixels are arranged as 1x1 areas. Area boundaries, rather than their centers, are aligned.

The default is not uniform across the library; see the table in Conventions & Pitfalls.