Prof. Dr. Ulrich Schwanecke
RheinMain University of Applied Sciences
1D Transformations
Primitives and Transformations
Original picture
Euclidean Transformation: Translation by \(b\)
Similarity Tranformation: Translation by \(b\), Scale with \(a\)
Euclidean transformation: Translation by \(b\)
non homogeneous: \(x^\prime = (1,b)\begin{pmatrix}x \\ 1\end{pmatrix}\), homogeneous: \(\begin{pmatrix}x^\prime \\ 1\end{pmatrix} = \begin{pmatrix}1 & b \\ 0 & 1\end{pmatrix}\begin{pmatrix}x \\ 1\end{pmatrix}\)
Similarity transformation: Translation by \(b\), Scale with \(a\)
non homogeneous: \(x^\prime = (a,b)\begin{pmatrix}x \\ 1\end{pmatrix}\), homogeneous: \(\begin{pmatrix}x^\prime \\ 1\end{pmatrix} = \begin{pmatrix}a & b \\ 0 & 1\end{pmatrix}\begin{pmatrix}x \\ 1\end{pmatrix}\)
General form of homogeneous (projective) transformation matrices \(\mathbf{H}\) in 1D: \[\mathbf{H} = \begin{pmatrix} a & b \\ c & 1\end{pmatrix}\]
Points in 1D/2D/3D can be written in inhomogeneous coordinates as \[ x \in \mathbb{R}\quad \text{or} \quad \mathbf{x}=\begin{pmatrix}x \\ y \end{pmatrix} \in \mathbb{R}^2\quad \text{or} \quad \mathbf{x}=\begin{pmatrix}x \\ y \\ z \end{pmatrix} \in \mathbb{R}^3 \] or in homogenous coordinates as \[ \tilde{\mathbf{x}}=\begin{pmatrix}\tilde{x} \\ \tilde{w} \end{pmatrix} \in \mathbb{P}^1\quad \text{or} \quad \tilde{\mathbf{x}}=\begin{pmatrix}\tilde{x} \\ \tilde{y} \\ \tilde{w} \end{pmatrix} \in \mathbb{P}^2\quad \text{or} \quad \tilde{\mathbf{x}}=\begin{pmatrix}\tilde{x} \\ \tilde{y} \\ \tilde{z} \\ \tilde{w} \end{pmatrix} \in \mathbb{P}^3 \] where \(\mathbb{P}^n = \mathbb{R}^{n+1} \setminus \{\mathbf{0}\}\) is called projective space. Homogeneous vectors that differ only by scale are considered equivalent and define an equivalence class, thus homogeneous vectors are defined only up to scale.
An inhomogeneous vector \(\mathbf{x}\) is converted to a homogeneous vector \(\tilde{\mathbf{x}}\) as follows \[ \tilde{\mathbf{x}}= \begin{pmatrix}\tilde{x} \\ \tilde{w} \end{pmatrix} = \begin{pmatrix} x \\ 1 \end{pmatrix} =\bar{x} \quad \text{or} \quad \tilde{\mathbf{x}}= \begin{pmatrix}\tilde{x} \\ \tilde{y} \\ \tilde{w} \end{pmatrix} = \begin{pmatrix} x \\ y \\ 1 \end{pmatrix} = \begin{pmatrix} \mathbf{x} \\ 1 \end{pmatrix} = \bar{\mathbf{x}} \quad \text{or} \quad \tilde{\mathbf{x}}= \begin{pmatrix}\tilde{x} \\ \tilde{y} \\ \tilde{z} \\ \tilde{w} \end{pmatrix} = \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} \mathbf{x} \\ 1 \end{pmatrix} = \bar{\mathbf{x}} \] with the augmented vector \(\bar{\mathbf{x}}\). To convert in opposite direction one has to divide by \(\tilde{w}\): \[ \bar{\mathbf{x}} = \begin{pmatrix} \mathbf{x} \\ 1 \end{pmatrix} = \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \frac{1}{\tilde{w}} \tilde{\mathbf{x}} = \frac{1}{\tilde{w}} \begin{pmatrix} \tilde{x} \\ \tilde{y} \\ \tilde{z} \\ \tilde{w} \end{pmatrix} = \begin{pmatrix} \tilde{x} / \tilde{w} \\ \tilde{y} / \tilde{w} \\ \tilde{z} / \tilde{w} \\ 1 \end{pmatrix} \] Homogeneous points whose last element is \(\tilde{w} = 0\) can’t be represented with inhomogeneous coordinates. They are called ideal points or points at infinity.
2D lines can also be expressed using homogeneous coordinates \(\tilde{\mathbf{l}}=(a,b,c)^\top\) \[ \{\tilde{\mathbf{x}} \;|\; \tilde{\mathbf{l}}\tilde{\mathbf{x}} = 0 \} \quad\Leftrightarrow\quad \{x,y \;|\; ax + by + c = 0 \} \]
The cross product can be writen as the product of a skew-symmetric matrix and a vector: \[ \mathbf{a}\times\mathbf{b} = [\mathbf{a}]_\times \mathbf{b} = \underbrace{\begin{bmatrix} 0 & -a_3 & a_2 \\ a_3 & 0 & -a_1 \\ -a_2 & a_1 & 0 \end{bmatrix}}_{\text{skew-symmetric matrix $[\mathbf{a}]_\times$, i.e. $[\mathbf{a}]_\times^\top = -[\mathbf{a}]_\times$ }} \begin{pmatrix} b_1 \\ b_2 \\ b_3 \end{pmatrix} = \begin{pmatrix} a_2b_3 - a_3b_2 \\ a_3b_1 - a_1b_3 \\ a_1b_2 - a_2b_1 \end{pmatrix} \] with
In homogeneous coordinates, the intersection of two lines is given by \[ \tilde{\mathbf{x}} = \tilde{\mathbf{l}}_1 \times \tilde{\mathbf{l}}_2 = [\tilde{\mathbf{l}}_1]_ {\times} \tilde{\mathbf{l}}_2 \]
In homogeneous coordinates, the line joining two points is also given by \[ \tilde{\mathbf{l}} = \tilde{\mathbf{x}}_1 \times \tilde{\mathbf{x}}_2 = [\tilde{\mathbf{x}}_1]_{\times} \tilde{\mathbf{x}}_2 \]
The duality principle:
To every proposition of two-dimensional projective geometry exists a dual proposition which is obtained by interchanging the role of points and lines in the original proposition.
\[ \begin{array}{ccc} \mathbf{x} & \longleftrightarrow & \mathbf{l}\\[3mm] \mathbf{x}^T\mathbf{l}=0 & \longleftrightarrow & \mathbf{l}^T\mathbf{x}=0\\[3mm] \mathbf{x}=\mathbf{l}\times\mathbf{l^\prime} & \longleftrightarrow & \mathbf{l}=\mathbf{x}\times\mathbf{x^\prime} \end{array} \]
Translation (2 DoF):
Euclidean (Ridig, 3 DoF):
Similarity (4 DoF):
Affine (6 DoF):
Perspective (Homography, 8 DoF):
Estimate a homography from a set of 2D correspondences:
Let \(\mathcal{X} = \{\tilde{\mathbf{x}}_i, \tilde{\mathbf{x}}^\prime_i\}^{N}_{i=1}\) denote a set of \(N\) 2D-to-2D correspondences related by \(\tilde{\mathbf{x}}^\prime_i = \tilde{\mathbf{H}}\tilde{\mathbf{x}}_i\)
As the correspondence vectors are homogeneous, they have the same direction but may differ in magnitude. Thus the correspondences are related by \(\tilde{\mathbf{x}}^\prime_i \times \tilde{\mathbf{H}}\tilde{\mathbf{x}}_i = \mathbf{0}\)
Using \(\tilde{\mathbf{h}}^\top_k\) to denote the \(k\)’th row of \(\tilde{\mathbf{H}}\), this can be rewritten as a linear equation in \(\tilde{\mathbf{h}}\): \[ \underbrace{ \begin{bmatrix} \mathbf{0}^\top & -\tilde{w}_i^\prime\tilde{\mathbf{x}}_i^\top & \tilde{y}_i^\prime\tilde{\mathbf{x}}_i^\top \\ \tilde{w}_i^\prime\tilde{\mathbf{x}}_i^\top & \mathbf{0}^\top & -\tilde{x}_i^\prime\tilde{\mathbf{x}}_i^\top \\ -\tilde{y}_i^\prime\tilde{\mathbf{x}}_i^\top & \tilde{x}_i^\prime\tilde{\mathbf{x}}_i^\top & \mathbf{0}^\top \end{bmatrix}}_{\mathbf{A}_i} \underbrace{ \begin{bmatrix} \tilde{\mathbf{h}}_1 \\ \tilde{\mathbf{h}}_2 \\ \tilde{\mathbf{h}}_3 \end{bmatrix}}_{\tilde{\mathbf{h}}} = \mathbf{0} \]
Each point correspondence yields two equations. Stacking all equations into a \(2N \times 9\) dimensional matrix \(\mathbf{A}\) leads to the following constrained least squares problem \[ \begin{eqnarray*} \tilde{\mathbf{h}}^* &=& \text{argmin}_{\tilde{\mathbf{h}}} \|\mathbf{A}\tilde{\mathbf{h}}\|_2^2 + \lambda ( \|\tilde{\mathbf{h}}\|_2^2 - 1)\\ &=& \text{argmin}_{\tilde{\mathbf{h}}} \tilde{\mathbf{h}}^\top\mathbf{A}^\top\mathbf{A}\tilde{\mathbf{h}} + \lambda ( \tilde{\mathbf{h}}^\top\tilde{\mathbf{h}} - 1) \end{eqnarray*} \]
\(\tilde{\mathbf{h}}\) can be fixed to \(\|\tilde{\mathbf{h}}\|_2^2=1\) as \(\tilde{\mathbf{H}}\) is homogeneous (defined up to scale) and the trivial solution \(\tilde{\mathbf{h}}=0\) is not of interest
The solution to this optimization problem is the singular vector corresponding to the smallest singular value of \(\mathbf{A}\) (the last column of \(\mathbf{V}\) when decomposing \(\mathbf{A}=\mathbf{UDV}^\top\))
The resulting algorithm is called Direct Linear Transformation
Image Stitching
Perspective Distortion Correction
If a point \(\tilde{\mathbf{x}}\) is transformed by a perspective 2D transformation \(\tilde{\mathbf{H}}\) as \[ \tilde{\mathbf{x}}^\prime = \tilde{\mathbf{H}}\tilde{\mathbf{x}} \] for a transformed 2D line it must hold \[ 0= {\tilde{\mathbf{l}}^\prime}^\top \tilde{\mathbf{x}}^\prime = {\tilde{\mathbf{l}}^\prime}^\top \tilde{\mathbf{H}}\tilde{\mathbf{x}} = (\tilde{\mathbf{H}}^\top \tilde{\mathbf{l}}^\prime)^\top \tilde{\mathbf{x}} = \tilde{\mathbf{l}}^\top\tilde{\mathbf{x}} \] and therefore \[ \tilde{\mathbf{l}}^\prime = \tilde{\mathbf{H}}^{-\top}\tilde{\mathbf{l}} \]
Thus, the action of a projective transformation on a co-vector such as a 2D line or 3D plane can be represented by the transposed inverse of the matrix.
Transformation | Matrix | # DOF | Preserves |
---|---|---|---|
translation | \([\mathbf{I\quad t}]_{2\times 3}\) | 2 | orientation |
rigid (Euclidean) | \([\mathbf{R\quad t}]_{2\times 3}\) | 3 | length |
similarity | \([s\mathbf{R\quad t}]_{2\times 3}\) | 4 | angles |
affine | \([\mathbf{A\quad t}]_{2\times 3}\) | 6 | parallelism |
projective | \([\mathbf{H}]_{3\times 3}\) | 8 | straight lines |
3D planes can also be represented with homogeneous coordinates \(\tilde{\mathbf{m}}=(a,b,c,d)^\top\) as it holds
\[ \{\tilde{\mathbf{x}} \;|\; \tilde{\mathbf{m}}^\top\bar{\mathbf{x}}=0\} \quad\Leftrightarrow\quad \{x,y,z \;|\; ax+by+cz+d=0 \} \]
Transformation | Matrix | # DOF | Preserves |
---|---|---|---|
translation | \([\mathbf{I\quad t}]_{3\times 4}\) | 3 | orientation |
rigid (Euclidean) | \([\mathbf{R\quad t}]_{3\times 4}\) | 6 | length |
similarity | \([s\mathbf{R\quad t}]_{3\times 4}\) | 7 | angles |
affine | \([\mathbf{A\quad t}]_{3\times 4}\) | 12 | parallelism |
projective | \([\mathbf{H}]_{4\times 4}\) | 15 | straight lines |
When are two vectors \(\vec{a}\) and \(\vec{b}\) perpendicular?
Give the homogenous vector for line through the points \(\vec{x}=(1,2)^\top\) and \(\vec{y}=(3,4)^\top\).
Give the homogenous vector for the intersection of the lines \(x-y+1=0\) and \(x-y-1=0\).
A point is transformed by \(\begin{pmatrix} 3 & 0 & 0 \\ 0 & 2 & 0\\ 0 & 0 & 1 \end{pmatrix}\). What is the proper transformation for lines?