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, consists of the following main submodules:

  • transform: low-level interfaces to manipulate 2D images, with routines for rotating, scaling, translating and shearing; cropping functions in several modalities such as central crops and crop-and-resize; vertical and horizontal flips; resizing; functions to warp tensors given affine or perspective transformations; and utilities to compute the transformation matrices behind those operations.

  • camera: routines specific to different camera representations, such as the pinhole or orthographic models, including projecting and unprojecting points between the camera and the world frame.

  • conversions: conversions between angle representations (radians and degrees), coordinate normalization, and homogeneous to Euclidean coordinates. It also includes conversions between 3D rotation representations: quaternions, axis-angle, rotation matrices and Euler angles.

  • linalg: general rigid-body homogeneous transformations, with functions to transform points between frames and to compose, invert and compute relative transformations.

  • depth: layers to manipulate depth maps, such as computing 3D point clouds from depth maps and calibrated cameras, per-pixel surface normals, and warping frames given a calibrated camera setup.

The remaining submodules, listed below, cover bounding boxes and keypoints, calibration, epipolar geometry, homographies, Lie groups, named poses, lines, point clouds, quaternions, RANSAC, polynomial solvers and sub-pixel refinement.

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.