# 5.3: Two-Dimensional Image Transformations

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$

( \newcommand{\kernel}{\mathrm{null}\,}\) $$\newcommand{\range}{\mathrm{range}\,}$$

$$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$

$$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$

$$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$

$$\newcommand{\Span}{\mathrm{span}}$$

$$\newcommand{\id}{\mathrm{id}}$$

$$\newcommand{\Span}{\mathrm{span}}$$

$$\newcommand{\kernel}{\mathrm{null}\,}$$

$$\newcommand{\range}{\mathrm{range}\,}$$

$$\newcommand{\RealPart}{\mathrm{Re}}$$

$$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$

$$\newcommand{\Argument}{\mathrm{Arg}}$$

$$\newcommand{\norm}[1]{\| #1 \|}$$

$$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$

$$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

$$\newcommand{\vectorA}[1]{\vec{#1}} % arrow$$

$$\newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow$$

$$\newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vectorC}[1]{\textbf{#1}}$$

$$\newcommand{\vectorD}[1]{\overrightarrow{#1}}$$

$$\newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}}$$

$$\newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}}$$

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

$$\newcommand{\avec}{\mathbf a}$$ $$\newcommand{\bvec}{\mathbf b}$$ $$\newcommand{\cvec}{\mathbf c}$$ $$\newcommand{\dvec}{\mathbf d}$$ $$\newcommand{\dtil}{\widetilde{\mathbf d}}$$ $$\newcommand{\evec}{\mathbf e}$$ $$\newcommand{\fvec}{\mathbf f}$$ $$\newcommand{\nvec}{\mathbf n}$$ $$\newcommand{\pvec}{\mathbf p}$$ $$\newcommand{\qvec}{\mathbf q}$$ $$\newcommand{\svec}{\mathbf s}$$ $$\newcommand{\tvec}{\mathbf t}$$ $$\newcommand{\uvec}{\mathbf u}$$ $$\newcommand{\vvec}{\mathbf v}$$ $$\newcommand{\wvec}{\mathbf w}$$ $$\newcommand{\xvec}{\mathbf x}$$ $$\newcommand{\yvec}{\mathbf y}$$ $$\newcommand{\zvec}{\mathbf z}$$ $$\newcommand{\rvec}{\mathbf r}$$ $$\newcommand{\mvec}{\mathbf m}$$ $$\newcommand{\zerovec}{\mathbf 0}$$ $$\newcommand{\onevec}{\mathbf 1}$$ $$\newcommand{\real}{\mathbb R}$$ $$\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}$$ $$\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}$$ $$\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}$$ $$\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}$$ $$\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}$$ $$\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}$$ $$\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}$$ $$\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}$$ $$\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}$$ $$\newcommand{\laspan}[1]{\text{Span}\{#1\}}$$ $$\newcommand{\bcal}{\cal B}$$ $$\newcommand{\ccal}{\cal C}$$ $$\newcommand{\scal}{\cal S}$$ $$\newcommand{\wcal}{\cal W}$$ $$\newcommand{\ecal}{\cal E}$$ $$\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}$$ $$\newcommand{\gray}[1]{\color{gray}{#1}}$$ $$\newcommand{\lgray}[1]{\color{lightgray}{#1}}$$ $$\newcommand{\rank}{\operatorname{rank}}$$ $$\newcommand{\row}{\text{Row}}$$ $$\newcommand{\col}{\text{Col}}$$ $$\renewcommand{\row}{\text{Row}}$$ $$\newcommand{\nul}{\text{Nul}}$$ $$\newcommand{\var}{\text{Var}}$$ $$\newcommand{\corr}{\text{corr}}$$ $$\newcommand{\len}[1]{\left|#1\right|}$$ $$\newcommand{\bbar}{\overline{\bvec}}$$ $$\newcommand{\bhat}{\widehat{\bvec}}$$ $$\newcommand{\bperp}{\bvec^\perp}$$ $$\newcommand{\xhat}{\widehat{\xvec}}$$ $$\newcommand{\vhat}{\widehat{\vvec}}$$ $$\newcommand{\uhat}{\widehat{\uvec}}$$ $$\newcommand{\what}{\widehat{\wvec}}$$ $$\newcommand{\Sighat}{\widehat{\Sigma}}$$ $$\newcommand{\lt}{<}$$ $$\newcommand{\gt}{>}$$ $$\newcommand{\amp}{&}$$ $$\definecolor{fillinmathshade}{gray}{0.9}$$

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.

##### Example $$\PageIndex{1}$$

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.

##### Exercise $$\PageIndex{1}$$

Write out the following matrices. Simplify and give numerical answers to two decimal places:

1. $$\mathrm{R}\left(\frac{\pi}{2}\right)$$;
2. $$\mathrm{S}(3,2)$$;
3. $$\mathrm{R}\left(-\frac{\pi}{4}\right)$$;
4. $$\mathrm{S}(-1,1)$$.

Reflections

##### Exercise $$\PageIndex{2}$$

What does S(−1,1) do? S(1,−1)? S(−1,−1)? S(1,1)?

##### Exercise $$\PageIndex{3}$$

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.

##### Exercise $$\PageIndex{4}$$

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$$.

This page titled 5.3: Two-Dimensional Image Transformations is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Louis Scharf (OpenStax CNX) via source content that was edited to the style and standards of the LibreTexts platform.