Affine Transformations
A parametric (global) transformation sends every point of an image to by one rule, set by a few numbers. A linear transformation is a matrix, , and every one is a combination of scale, rotation, shear and mirror. In the lecture’s convention, with the -axis pointing up and meaning counterclockwise, these are
Here are scale factors ( is uniform scaling) and are shear factors. Linear maps send the origin to the origin and lines to lines. They keep parallel lines parallel and preserve ratios of lengths along a line. They are closed under composition. Translation is not linear, because it moves the origin.In homogeneous coordinates the 3-vector with is the point . So , and are one point, is a point at infinity in direction , and is not allowed. An affine transformation is a linear map followed by a translation, written as one matrix:
The block is the linear part and is the translation. An affine map keeps every property of linear maps except that the origin need not map to the origin, and it models a change of coordinates. Composition is matrix multiplication read right to left: scales, then rotates, then translates.The transformation classes are nested groups: each is closed under composition and contains the inverse of each member. Each class also preserves everything that the more general classes preserve. One point correspondence gives two equations, so a class with degrees of freedom (DoF) needs pairs, rounded up. Translation, , has DoF, needs pair and preserves orientation. A Euclidean (rigid) map, , has DoF, needs pairs and preserves lengths. A similarity, , has DoF, needs pairs and preserves angles. An affine map, , has DoF, needs pairs and preserves parallelism and ratios of lengths along a line. A projective map (homography), , has DoF, needs pairs and preserves straight lines. Three non-collinear point pairs, such as the corners of two triangles, fix a unique affine map.
Rotation Sign in Image Coordinates
The lecture’s turns points counterclockwise when the -axis points up. Image arrays index rows downward, so grows toward the bottom of the screen. With pointing down, the same matrix with turns the picture clockwise on screen. Some references write the matrix with the signs of the sines swapped, . That matrix is , the inverse rotation. Fix one convention per project and test it on a single point before warping a whole image.
Intuition
Image filtering changes the range of an image: changes the values. Image warping changes the domain: it moves values to new places, . A parametric, or global, warp uses one rule for every pixel, and a few numbers describe it. Think of as a machine that takes coordinates in and gives coordinates out. The simplest such machines are matrices. The columns of a matrix are the places where and land. So choosing a matrix is the same as choosing a new pair of axes and redrawing the grid along them. The figure shows the basic warps applied to a unit square. The dot marks where the corner at the origin goes. The blue shapes keep parallel lines parallel, and the red projective shape does not.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x=1.1cm,y=1.1cm,>=latex]
\foreach \cx/\cy in {0/0,3.4/0,6.8/0,0/-3.2,3.4/-3.2,6.8/-3.2}{
\begin{scope}[shift={(\cx,\cy)}]
\draw[->,mid] (-0.7,0) -- (1.9,0) node[right] {\scriptsize $x$};
\draw[->,mid] (0,-0.5) -- (0,1.7) node[above] {\scriptsize $y$};
\draw[mid,dashed] (0,0) rectangle (1,1);
\end{scope}
}
\begin{scope}[shift={(0,0)}]
\draw[very thick,cold,fill=cold!15] (0.5,0.3) -- (1.5,0.3) -- (1.5,1.3) -- (0.5,1.3) -- cycle;
\fill (0.5,0.3) circle (1.8pt); \node at (0.6,-0.9) {translation, $2$ DoF};
\end{scope}
\begin{scope}[shift={(3.4,0)}]
\draw[very thick,cold,fill=cold!15] (0,0) -- (0.866,0.5) -- (0.366,1.366) -- (-0.5,0.866) -- cycle;
\fill (0,0) circle (1.8pt); \node at (0.6,-0.9) {rotation, $1$ DoF};
\end{scope}
\begin{scope}[shift={(6.8,0)}]
\draw[very thick,cold,fill=cold!15] (0,0) -- (1.5,0) -- (1.5,0.6) -- (0,0.6) -- cycle;
\fill (0,0) circle (1.8pt); \node at (0.6,-0.9) {scale, $2$ DoF};
\end{scope}
\begin{scope}[shift={(0,-3.2)}]
\draw[very thick,cold,fill=cold!15] (0,0) -- (1,0) -- (1.5,1) -- (0.5,1) -- cycle;
\fill (0,0) circle (1.8pt); \node at (0.6,-0.9) {shear, $2$ DoF};
\end{scope}
\begin{scope}[shift={(3.4,-3.2)}]
\draw[very thick,cold,fill=cold!15] (0.2,0.1) -- (1.4,-0.2) -- (1.8,0.6) -- (0.6,0.9) -- cycle;
\fill (0.2,0.1) circle (1.8pt); \node at (0.6,-0.9) {affine, $6$ DoF};
\end{scope}
\begin{scope}[shift={(6.8,-3.2)}]
\draw[very thick,hot,fill=hot!15] (0,0) -- (1.3,0.15) -- (1.0,0.95) -- (0.15,0.75) -- cycle;
\fill (0,0) circle (1.8pt); \node at (0.6,-0.9) {projective, $8$ DoF};
\end{scope}
\end{tikzpicture}
\end{document}A matrix cannot move the origin, since . Homogeneous coordinates get around this. They place the image plane at height inside 3D space. Each 2D point becomes a ray through the 3D origin, and every point on that ray names the same 2D point. A matrix acts linearly on the rays. When its bottom row is , it maps the plane to itself, so it acts on the image as a linear map plus a translation. In 3D the translation part is a shear, , which is linear. A ray that lies flat in the plane never meets the image plane. It stands for a direction, and that is what a point at infinity means.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x={(0.9cm,0cm)},y={(0.6cm,0.25cm)},z={(0cm,1.3cm)},>=latex]
\fill[cold!12] (-0.5,0,1) -- (7,0,1) -- (7,4,1) -- (-0.5,4,1) -- cycle;
\draw[cold] (-0.5,0,1) -- (7,0,1) -- (7,4,1) -- (-0.5,4,1) -- cycle;
\node[cold,above] at (-0.5,4,1) {image plane $w = 1$};
\draw[->] (0,0,0) -- (7.6,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,3,0) node[right] {$y$};
\draw[->] (0,0,0) -- (0,0,3.6) node[above] {$w$};
\draw[thick,hot] (0,0,0) -- (7.2,3.6,3.6);
\fill[hot] (2,1,1) circle (1.8pt);
\fill[hot] (4,2,2) circle (1.8pt);
\fill[hot] (6,3,3) circle (1.8pt);
\node[hot,below right] at (2,1,1) {$(2,1,1)$};
\node[hot,left] at (4,2,2) {$(4,2,2)$};
\node[hot,left] at (6,3,3) {$(6,3,3)$};
\node[hot,right] at (7.2,3.6,3.6) {all name the point $(2,1)$};
\draw[thick,mid,dashed,->] (0,0,0) -- (4,2,0);
\node[mid,right] at (4,2,0) {$(2,1,0)$: a point at infinity, never meets $w = 1$};
\end{tikzpicture}
\end{document}Properties
(Triangle to Triangle) Three point pairs fix an affine map, and there are two ways to compute it.
The algebraic way writes and for each of the three pairs. This gives six linear equations in the six unknowns , solved as a system. The solution is unique when the three source points are not collinear. The geometric way goes through the unit triangle with corners , and . The matrix
sends to , to and to . Its first two columns are the edge vectors and , and its last column is the new origin . The lecture’s reminder “don’t forget to move the origin too” refers to this last column. Build the same way from . Then first goes back from to the unit triangle and then forward to . The unit-triangle coordinates are the barycentric coordinates of , since . The name comes from the barycenter, or center of mass: masses , and placed at , and balance at . An affine map keeps these weights. A point with given barycentric coordinates in maps to the point with the same coordinates in . This is the step that image morphing repeats for every triangle. The figure shows the triangles of the third example below. The red point has in all three.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x=0.85cm,y=0.85cm,>=latex]
\draw[thick,fill=mid!15] (1,1) -- (3,2) -- (2,4) -- cycle;
\draw[->,very thick,cold] (1,1) -- (3,2);
\draw[->,very thick,cold] (1,1) -- (2,4);
\fill (1,1) circle (2pt) node[below left] {$A = (1,1)$};
\node[right] at (3,2) {$B = (3,2)$};
\node[left] at (2,4) {$C = (2,4)$};
\node[cold,below right] at (2.0,1.45) {\small $B - A$};
\node[cold,left] at (1.45,2.6) {\small $C - A$};
\fill[hot] (2.1,2.8) circle (2pt);
\node at (2,0) {source};
\begin{scope}[shift={(5.2,4.8)},scale=1.6]
\draw[thick,fill=mid!15] (0,0) -- (1,0) -- (0,1) -- cycle;
\node[below left] at (0,0) {\small $(0,0)$};
\node[below right] at (1,0) {\small $(1,0)$};
\node[above] at (0,1) {\small $(0,1)$};
\fill[hot] (0.3,0.5) circle (1.3pt);
\draw[hot] (0.3,0.5) -- (0.75,0.85) node[right] {\small $(\beta,\gamma)$};
\end{scope}
\draw[->,thick] (5.1,5.6) -- (2.5,4.3) node[midway,above left] {$T_1$};
\draw[->,thick] (6.9,5.1) -- (9.6,4.6) node[midway,above right] {$T_2$};
\begin{scope}[shift={(7,0)}]
\draw[thick,fill=mid!15] (1,2) -- (4,1) -- (5,4) -- cycle;
\fill (1,2) circle (2pt) node[left] {$A' = (1,2)$};
\node[below] at (4,1) {$B' = (4,1)$};
\node[above] at (5,4) {$C' = (5,4)$};
\fill[hot] (3.9,2.7) circle (2pt);
\node at (3,0) {destination};
\end{scope}
\draw[->,very thick] (3.6,0.9) -- (7.6,0.9) node[midway,below] {$T = T_2 T_1^{-1}$};
\end{tikzpicture}
\end{document}(Composition Order) The rightmost matrix acts first, and swapping two factors usually changes the map.
To rotate by about a point instead of the origin, move to the origin, rotate, and move back: . Writing the factors in another order rotates about a different point. Scaling and translation do not commute either. The product shifts by and then scales the shift as well, so the net shift is . The product shifts by exactly . Two rotations about the same point do commute, and .
(Reading Off Columns) The columns of a transformation matrix are the images of the axes and of the origin.
A linear map sends to its first column and to its second. So the matrix with columns and converts coordinates in the basis to standard coordinates. For example, the point has standard coordinates . This is why the lecture says that any linear transformation is a basis, as in change of basis. Going the other way needs the inverse . When and are orthonormal, the inverse is the transpose (orthonormal matrices). The new coordinates are then the dot products , as in inner products. A full coordinate frame adds an origin , and its matrix is
maps frame coordinates to world coordinates. The lecture defines a frame by an origin and two unit axes, but its worked example uses an axis of length . The column rule works for any two non-parallel axes. Only the transpose shortcut needs orthonormal axes.
(Inverses Stay in Class) The inverse of an affine map is affine and has a closed form.
Write the map as , with linear part . Solving for gives
where . The inverse exists exactly when . The basic inverses are , and . Inverse warping applies this inverse at every output pixel. A map with squashes the plane onto a line or a point and cannot be undone.
(The Last Row) The bottom row keeps and sends points at infinity to points at infinity.
The lecture asks whether the last coordinate always stays . For an affine matrix it does, so no division is needed after the multiplication. A point at infinity maps to , which is again at infinity. Parallel lines meet at a point at infinity, so their images also meet at infinity and stay parallel. A projective matrix has a general bottom row . Then changes from point to point, the result must be divided by , and a point at infinity can land at a finite vanishing point. That is the extra freedom of a homography.
Derivation
We want the matrix that turns every point by about the origin. Write a point in polar coordinates as and , where is its distance from the origin and is its angle from the -axis. A rotation keeps and adds to the angle:
The angle-sum identities expand these to
Substituting and gives and , which is . The map is linear in even though and are not linear in . For a fixed angle they are constant coefficients.
Examples
(Easy) Rotating a Photo About Its Center
A photo has its center at . We want to rotate it by about the center with the lecture’s .
Build the matrix. Where do the corners and go? What goes wrong if the factors are multiplied in the opposite order? The matrix is . With and , the linear part is . The translation column is , so The corner goes to and the corner goes to . The center goes to itself, as it should. The negative coordinate shows that the rotated photo sticks out of the old canvas, which is why a warp must first compute the output's bounding box.
The opposite order is also a rotation, but about the point . It sends the center to , far off the canvas. Dropping both translations rotates about the top-left corner .
(Medium) Placing a Watermark With Its Own Frame
A watermark is designed in its own coordinates . It is placed on a photo with origin and axes and , all in pixel coordinates. The axes are orthonormal.
Write the frame matrix . Where does the watermark point land? Which watermark point lies under the photo pixel ? The columns of are , and : Then , so the point maps to pixel .
For the reverse direction, first subtract the origin: . The axes are orthonormal, so the frame coordinates are dot products: and . The answer is . The same result comes from
Taking dot products with directly, without subtracting , gives , which is wrong by the origin’s offset.
(Hard) Warping One Triangle of a Face Mesh
A face mesh has a triangle , , in one photo. The matching triangle in a second photo is , , .
Find the affine map with the system and with . Where does the point with barycentric weights go? What happens if the origin column is forgotten? Each pair gives one equation for and one for : The solution is , , , , , .
For the geometric way, the edge vectors are , , and . So
The product is , the same map. Its linear part has determinant , so the triangle’s area doubles, from to .The point has unit-triangle coordinates , which are and . Then , which equals . The weights carry over unchanged.
If the last columns and are replaced by zeros, the result is . It has the right linear part but no translation. It sends to instead of .
See Also
- 3.5. Image Morphing, which uses one affine map per triangle.
- 5.1. The Pinhole Camera, whose extrinsics are a rigid transformation in 3D.