5.3: Two-Dimensional Image Transformations
We now turn our attention to operating on the point matrix \(G\) to produce the desired transformations. We will consider rotation scaling and translation (moving) of objects. Rotation and scaling are done by matrix multiplication with a square transformation matrix \(A\). If we call the transformed point matrix \(\mathrm{G}_{\text {new }}\), we have
\[\left[\mathrm{G}_{\text {new }}\right]=[\mathrm{A}][\mathrm{G}] \nonumber \]
We call \(A\) a matrix operator because it “operates” on \(G\) through matrix multiplication. In contrast, translation must be done by matrix addition.
In a later section you will see that it is advantageous to perform all operations by matrix operators and that we can modify our image representation to allow translation to be done with a matrix operator like rotation and scaling. We will call the modified representation homogeneous coordinates .
Rotation
We saw in the chapter on linear algebra that the matrix that rotates points by an angle \(\theta\) is
\[A=R(\theta)=\left[\begin{array}{cc}
\cos \theta & -\sin \theta \\
\sin \theta & \cos \theta
\end{array}\right] \nonumber \]
When applied to the point matrix \(G\), this matrix operator rotates each point by the angle \(\theta\), regardless of the number of points.
We can use the rotation matrix to do the single point rotation of the example from "Vector Graphics: Introduction" . We have a point matrix consisting of only the point (3,1):
\[\mathrm{G}=\left[\begin{array}{l}
3 \\
1
\end{array}\right] \nonumber \]
The necessary transformation matrix is \(R(\theta)\) with \(\theta = \frac{\pi}{6}\). Then the rotated point is given by
\[\mathrm{G}_{\text {new }}=\mathrm{R}\left(\frac{\pi}{6}\right) \mathrm{G}=\left[\begin{array}{ll}
\cos \left(\frac{\pi}{6}\right) & -\sin \left(\frac{\pi}{6}\right) \\
\sin \left(\frac{\pi}{6}\right) & \cos \left(\frac{\pi}{6}\right)
\end{array}\right]\left[\begin{array}{l}
3 \\
1
\end{array}\right] \approx\left[\begin{array}{l}
2.10 \\
2.37
\end{array}\right] \nonumber \]
Scaling
An object can be enlarged or reduced in each dimension independently. The matrix operator that scales an image by a factor of \(s_x\) along the x-axis and \(s_y\) along the y-axis is
\[\mathrm{A}=\mathrm{S}\left(s_{x}, s_{y}\right)=\left[\begin{array}{ll}
s_{x} & 0 \\
0 & s_{y}
\end{array}\right] \nonumber \]
Most often we take \(s_x=s_y\) to scale an image by the same amount in both dimensions.
Write out the following matrices. Simplify and give numerical answers to two decimal places:
- \(\mathrm{R}\left(\frac{\pi}{2}\right)\);
- \(\mathrm{S}(3,2)\);
- \(\mathrm{R}\left(-\frac{\pi}{4}\right)\);
- \(\mathrm{S}(-1,1)\).
Reflections
What does S(−1,1) do? S(1,−1)? S(−1,−1)? S(1,1)?
Given \(G=\left[\begin{array}{llll}
0 & -1.5 & 4 & 4 \\
0 & 5 & 2.3 & -1
\end{array}\right]\) and \(\theta=\frac{\pi}{3}\) find \(\mathrm{G}_{\text {new }}=\mathrm{R}(\theta) \mathrm{G}\). Give numerical answers to two decimal places.
Apply each of the transformations in Exercise 1 and 2 to the image
\[\mathrm{G}=\left[\begin{array}{llll}
1 & 1 & 2 & 2 \\
1 & 2 & 2 & 1
\end{array}\right] ; \quad \mathrm{H}=\left[\begin{array}{llll}
1 & 2 & 3 & 4 \\
2 & 3 & 4 & 1
\end{array}\right] \nonumber \]
Sketch the original image and each transformation of it.
Translation
An object can be moved by adding a constant vector \(b\) to every point in the object. For example, \(b=\left[\begin{array}{l}
20 \\
-5
\end{array}\right]\) will move an object 20 units to the right and 5 units down. We can write this in terms of the point matrix as
\[\mathrm{G}_{\text {new }}=\mathrm{G}+\mathrm{b} 1^{T} \nonumber \]
where 1 (read “the one-vector”) is a vector of \(n\) 1's:
\[1=\left[\begin{array}{c}
1 \\
1 \\
\vdots \\
1
\end{array}\right] \nonumber \]
In MATLAB, 1 may be obtained by ones(n, 1) . The outer product of \(b\) with 1 in Equation 7 simply serves to make \(n\) copies of \(b\) so that one copy can be added to each point in \(G\).