Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
In computer vision and image processing, affine transformation and homography are essential techniques used to align images and correct geometric distortions.
In this tutorial, we’ll recall the mathematical definitions of affine transformation and homography. Then we’ll explain the difference between them by providing illustrative examples.
An affine transformation is represented by a function composition of a linear transformation with a translation.
The affine transformation of a given vector is defined as:
where is the transformed vector,
is a square and invertible matrix of size
and
is a vector of size
.
In geometry, the affine transformation is a mapping that preserves straight lines, parallelism, and the ratios of distances. This means that:
On the other hand, affine transformations do not necessarily preserve lengths and angles.
The following figure shows an example of an affine transformation applied to a checkered image:

In the 2D case, the affine transformation is given by the equations:
that can be expressed in a single product matrix-vector using the homogeneous coordinates:
The matrix elements of the affine transform have the following meanings:
Translation, scaling, rotation, and shearing are particular types of affine transformations. In fact, a translation is represented by a matrix of the form:
while the scaling matrix is:
and the shearing matrix is:
The homography, also known as perspective transform, is a geometric transformation that relates two different planes:

Looking at the figure above, each point of the plane
is related to a point
in the plane
using the following equation operating on the homogeneous coordinates:
where is a scale factor and
is a
matrix called the homography matrix:
Two homography matrices are equivalent if they differ only by a scale factor. Hence, the matrix is generally normalized with
.
The inhomogeneous coordinates of the transformed point are computed as follows:
Homography is a mapping that preserves straight lines, i.e., points that are on the same line initially lie on a line after the transformation.
The following figure shows an example of homography applied to a checkered image:

While both affine transformation and homography are types of geometric transformations that can be used to map one image onto another, there are some key differences between them:
An affine transformation preserves straight and parallel lines, while homography preserves only straight lines. This means that points that are collinear before an affine transformation remain collinear after the transformation, but this is not necessarily the case for homographies.
Another difference is the number of degrees of freedom. An affine transformation has 6 degrees of freedom, as it can be represented by a matrix with 6 coefficients. A homography has 8 degrees of freedom, as it can be represented by a
matrix with eight free parameters.
The third difference is the type of distortion they can correct. Affine transformations can correct for translations, rotations, shears, and scales, but they cannot be correct for perspective distortion. Homographies, on the other hand, can correct for perspective distortion, as well as translations, rotations, shears, and scales.
Here are some applications of affine transformation and homography in computer vision and image processing:
In this article, we reviewed affine transformation and homography, two essential techniques used to align and correct geometric distortion in images. We discussed their differences and provided their main applications in image processing and computer vision.