AI Glossary / Computer vision and multimodal AI / Intermediate
Affine transformation
Definition
An affine transformation maps coordinates using a linear transformation followed by a translation. In image geometry, it can represent rotation, scaling, shear, reflection and movement while preserving straightness and, for invertible transformations, parallel lines.
What it means
Imagine moving or reshaping a flat image according to one consistent coordinate rule. Every point follows the same formula. A rectangle may become a parallelogram, but the rule does not independently bend one corner into a curve.
Affine transformations are useful when an image needs alignment, a drawing needs resizing or training images need controlled geometric variation. They are more flexible than a translation alone, but less flexible than a general projective transformation or a free-form warp.
They do not generally preserve angles, lengths or circles. Uniform scaling and rotation have special properties that an arbitrary affine map does not share. A shear, for example, changes angles while keeping the relevant lines parallel.
How it works
In two dimensions, a point (x, y) can be mapped to x' = ax + by + tx and y' = cx + dy + ty. The four coefficients a, b, c and d describe the linear part; tx and ty describe translation. Software often stores all six in a 2-by-3 matrix.
Three non-collinear point correspondences can determine a general two-dimensional affine map when the data are consistent. With additional noisy correspondences, an estimation method can fit a map and examine residual errors. Outliers need appropriate handling rather than blind averaging.
For image warping, the coordinate map alone is not the entire operation. The output pixels must receive sampled image values, often by inverse mapping and interpolation. Border treatment, output dimensions and interpolation choice affect the resulting picture even when the transformation matrix is identical.
Three practical examples
- A document-processing system corrects a small in-plane rotation before attempting text recognition.
- A graphics editor scales, rotates and positions a logo within a layout.
- A vision team creates modest affine variations of training images and transforms the corresponding annotations consistently.
Think of it this way
Think of a picture printed on an ideal sheet that can be uniformly stretched, sheared, rotated and moved without being locally bent. A grid remains a grid of straight lines, although squares may become parallelograms. The analogy is limited: real material deformation is rarely exactly uniform, and a mathematical affine map can also collapse a dimension if its linear part is singular.
Worked example
Let the transformation be x' = 2x + 0.5y + 3 and y' = y − 1. A point (4, 2) becomes x' = 8 + 1 + 3 = 12 and y' = 1, giving (12, 1).
A second point (6, 2) becomes (16, 1). The original horizontal displacement of two units becomes four units. A point (4, 4) becomes (13, 3), showing that increasing y also shifts x because of the shear term 0.5y.
The translation moves all points equally after the linear calculation. Changing the order of separate operations can change the result: translating before scaling usually differs from translating afterward. This example maps coordinates only; producing a raster image requires a sampling rule as well.
Illustrative case study
Fictional example: Pagewise Services receives scans with small orientation and placement differences. The team uses printed reference marks to estimate a transformation into a standard page layout.
It first checks whether an affine model is adequate. Most scans align, but photographs taken at a steep angle retain perspective distortion. The team routes those images to a more suitable correction process instead of forcing every input through the same six-parameter model.
Reviewers inspect text baselines and reference-mark residuals. The original scans remain available, and the transformation settings accompany processed files. This fictional workflow illustrates model selection and traceability; it does not claim a measured recognition improvement.
Common misconceptions and mistakes
An affine map is not automatically a rigid motion. Nonuniform scaling and shear can change shape measurements. It also does not model all perspective effects: converging parallel lines in a photograph may require a projective model.
A matrix with six numbers is not proof that the estimated transformation is appropriate. Nearly collinear reference points can make estimation unstable. Repeatedly warping an image can accumulate resampling damage, even if the combined coordinate transformation is simple. Bounding boxes and masks also require deliberate treatment; transforming an image while leaving its labels unchanged creates inconsistent training data.
Business use
Affine transformations offer a compact, interpretable tool for alignment and controlled augmentation. They are useful where the expected geometry fits their assumptions and where a more complex warp would add unnecessary flexibility.
Define the coordinate convention, reference points, output canvas and interpolation method. Check whether important content moves outside the canvas and whether measurements remain meaningful after scaling. When combining several edits, composing their matrices before a single resampling step can reduce repeated interpolation. Judge alignment using independent features as well as the points used to fit the map.
People also ask
Does an affine transformation preserve distances?
Not in general. Rigid motions do, while general scaling and shear can change them.
Can it turn a straight line into a curve?
No. An affine map preserves collinearity, though a singular map can collapse a line to a point.
Is affine the same as perspective correction?
No. Some small distortions can be approximated affinely, but a general perspective mapping has additional flexibility.
Check your understanding
A transformed rectangle becomes a parallelogram with straight, parallel opposite sides. Does that necessarily violate an affine model?
Answer: No. Shear can produce exactly that result. Preserving right angles is not a requirement of a general affine transformation.
Related terms
- Scaling
- Image registration
- Translation
- rotation
- shear
- homogeneous coordinates
- projective transformation
- homography
- interpolation
Learn next
Plot three points and apply the worked transformation by hand. Then add a fourth point and check the predicted location. Compare a rotation-only map, a shear and a perspective warp on a simple grid. Observe which properties remain unchanged, and separate coordinate errors from artifacts caused by image interpolation.
More in Computer vision and multimodal AI
- Adaptive sharpening - Adaptive sharpening increases the apparent clarity of image detail while varying its strength according to local image conditions.
- Additive color - Additive color is the production of color by combining light.
- Affine bilateral grid (HDRnet) - An affine bilateral grid in HDRnet stores local color-transformation coefficients in a compact grid indexed by image position and a guidance value.
- Affinity - In image processing, affinity is a numerical weight describing how strongly two pixels or image elements should influence one another.
- Age progression - Age progression is the creation of an image showing how a person's appearance might change as they become older.
- Airlight - Airlight is light scattered by the atmosphere into the camera's line of sight.
Sources
OpenCV, Affine Transformations tutorial: https://docs.opencv.org/4.x/d4/d61/tutorial_warp_affine.html OpenCV, geometric image transformations reference: https://docs.opencv.org/4.x/da/d54/group__imgproc__transform.html The numerical map and Pagewise case are original teaching examples. The discussion concerns image geometry; affine colour transformations apply the same algebraic form to colour vectors.
Previous: Affine calibration Next: Affinity