# Image Transformation <style> figure { padding: 4px; margin: auto; text-align: center; } figcaption { background-color: black; color: white; font-style: italic; padding: 1px; text-align: center; } </style> ## Transformation in 2D Let us start from 2D space, and then extend the concept to 3D space later. Noted that we use the homogeneous coordinates in this post. So matrix $M_{3 \times 3}$ is actually a 2D -> 2D transformation. | Name | Matrix | #DoF | Preserves | Shape | | -------- | -------- | -------- |--- |--- | | translation | $\begin{bmatrix} I & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 3}$ | 2 | orientation + ... | <img src="https://hackmd.io/_uploads/B1eQG25qT.png" width="50"> | | rigid |$\begin{bmatrix} R & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 3}$ | 3 | lengths + ... | <img src="https://hackmd.io/_uploads/SJXvG3q5p.png" width="50"> | similarity | $\begin{bmatrix} sR & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 3}$ | 4 | angles + ... | <img src="https://hackmd.io/_uploads/SJXvG3q5p.png" width="60"> | | affine | $\begin{bmatrix} A & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 3}$ | 6 | parallelism + ... | <img src="https://hackmd.io/_uploads/S1yiz35c6.png" width="60"> | | perspective | $\begin{bmatrix} A & t \\ v^{T} & 1 \end{bmatrix}_{3 \times 3}$ | 8 | straight lines + ... | <img src="https://hackmd.io/_uploads/BkX2fhqc6.png" width="60"> | The matrix representation can be specifically written as follow: 1. Translation transformation: $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & t_{x} \\ 0 & 1 & t_{y} \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}= \begin{bmatrix} I & t \\ 0^{T} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$ ==DoF is 2: $t_{x}, t_{y}$== 1. Euclidean / Rigid / Isometric transformation: $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} cos \theta & -sin \theta & t_{x} \\ sin \theta & cos \theta & t_{y} \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} R & t \\ 0^{T} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$ ==DoF is 3: $\theta, t_{x}, t_{y}$== <figure> <img src="https://hackmd.io/_uploads/H1vvD2bcp.gif" width="200"> </figure> 2. Similarity transformation: $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} s ~ cos \theta & -s ~ sin \theta & t_{x} \\ s ~ sin \theta & s ~ cos \theta & t_{y} \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} sR & t \\ 0^{T} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$ ==DoF is 4: $s, \theta, t_{x}, t_{y}$== <figure> <img src="https://hackmd.io/_uploads/S1SdD3-cp.gif" width="200"> </figure> 3. Affine transformation: $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} a & b & t_{x} \\ c & d & t_{y} \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} A & t \\ 0^{T} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$ ==DoF is 6: $a, b, c, d, t_{x}, t_{y}$== <figure> <img src="https://hackmd.io/_uploads/r12OwnW5T.gif" width="200"> </figure> 4. Perspective / Projective / Homography transformation: $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} a & b & t_{x} \\ c & d & t_{y} \\ v_{1} & v_{2} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} A & t \\ v^{T} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$ ==DoF is 8: $a, b, c, d, v_{1}, v_{2}, t_{x}, t_{y}$== <figure> <img src="https://hackmd.io/_uploads/H1wtwhbca.gif" width="200"> </figure> ## Transformation in 3D | Name | Matrix | #DoF | Preserves | Shape | | -------- | -------- | -------- |--- |--- | | translation | $\begin{bmatrix} I & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 4}$ | 3 | orientation + ... | <img src="https://hackmd.io/_uploads/SyFMEh55a.png" width="50"> | | rigid |$\begin{bmatrix} R & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 4}$ | 6 | lengths + ... | <img src="https://hackmd.io/_uploads/B1cQEh556.png" width="50"> | similarity | $\begin{bmatrix} sR & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 4}$ | 7 | angles + ... | <img src="https://hackmd.io/_uploads/B1cQEh556.png" width="60"> | | affine | $\begin{bmatrix} A & t \\ 0^{T} & 1 \end{bmatrix}_{3 \times 4}$ | 12 | parallelism + ... | <img src="https://hackmd.io/_uploads/HJbSV2956.png" width="60"> | | perspective | $\begin{bmatrix} A & t \\ v^{T} & 1 \end{bmatrix}_{3 \times 4}$ | 15 | straight lines + ... | <img src="https://hackmd.io/_uploads/ByurE3ccp.png" width="60"> | 1. Euclidean / Rigid / Isometric transformation: $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} R & t \\ 0^{T} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$ $$ R = \begin{bmatrix} 1 & 0 & 0\\ 0 & cos ~\alpha & -sin ~\alpha \\ 0 & sin ~\alpha & cos ~\alpha \end{bmatrix} \begin{bmatrix} cos ~\beta & 0 & sin ~\beta\\ 0 & 1 & 0 \\ -sin ~\beta & 0 & cos ~\beta \end{bmatrix} \begin{bmatrix} cos ~\gamma & -sin ~\gamma & 0\\ sin ~\gamma & cos ~\gamma & 0 \\ 0 & 0 & 1 \end{bmatrix} $$ $$ t = \begin{bmatrix} t_{x} \\ t_{y} \\ t_{z} \end{bmatrix} $$ ==DoF is 6: $\alpha, \beta, \gamma, t_{x}, t_{y}, t_{z}$== ## Reference - https://medium.com/@insight-in-plain-sight/deconstructing-the-homography-matrix-35989ecc0b2