Affine Transformation
A linear geometric transformation combining translation, rotation, scaling, and shearing that preserves parallel lines while deforming image geometry - a fundamental image processing operation.
An affine transformation combines translation, rotation, scaling, and shearing while preserving straight lines and parallelism. It is fundamental to image resizing, rotation, skew correction, and data augmentation in machine learning.
Represented by a 2×3 matrix:
- Format:
[[a, b, tx], [c, d, ty]]where(a, b, c, d)encode linear transformation and(tx, ty)encode translation - 6 degrees of freedom, determined by 3 point correspondences
- In homogeneous coordinates: 3×3 matrix with bottom row
[0, 0, 1]
Common types:
- Translation: Only
tx, tyset. Shifts the image horizontally and vertically - Rotation:
a=cos(theta), b=-sin(theta), c=sin(theta), d=cos(theta) - Scaling:
a=sx, d=sy. Scales each axis independently - Shearing: Non-zero
borc. Skews the image diagonally
In OpenCV, cv2.getAffineTransform() computes the matrix from 3 points and cv2.warpAffine() applies it. Random affine transforms are a standard data augmentation technique in deep learning, improving model generalization by exposing networks to geometric variations.