Skip to main content

Module perspective_transform

Module perspective_transform 

Source
Expand description

GPU-accelerated perspective transform and lens distortion correction.

This module provides two closely related geometric operations:

  1. Perspective (homography) transform: maps a quadrilateral region of the source image to a rectangle in the output (or vice versa). The transform is specified as a 3×3 homography matrix.

  2. Lens distortion correction: removes barrel or pincushion distortion using the Brown-Conrady radial/tangential distortion model.

Both operations use backward-mapping with bilinear interpolation: for each output pixel the inverse transform is applied to find the corresponding source location, which is then sampled bilinearly from the input.

All heavy work is parallelised over rows using rayon.

§Example

use oximedia_gpu::perspective_transform::{
    HomographyMatrix, PerspectiveTransform, LensDistortionParams, LensDistortionCorrector,
};

let src = vec![0u8; 640 * 480 * 4];
let mut dst = vec![0u8; 640 * 480 * 4];

// Identity transform
let h = HomographyMatrix::identity();
PerspectiveTransform::new(h)
    .warp_rgba(&src, 640, 480, &mut dst, 640, 480)
    .unwrap();

Structs§

HomographyMatrix
A 3×3 homography (perspective transform) matrix stored in row-major order.
LensDistortionCorrector
Lens distortion corrector.
LensDistortionParams
Brown-Conrady radial and tangential lens distortion parameters.
PerspectiveTransform
Perspective (homography) transform applied to RGBA images.