linear algebra ii - UCL Computer Science - Home · GV01 - Mathematical Methods, Algorithmics and...
Transcript of linear algebra ii - UCL Computer Science - Home · GV01 - Mathematical Methods, Algorithmics and...
GV01 - Mathematical Methods, Algorithmics and Implementations: Linear Algebra Part II – Linear Transformations
Simon Julier
Department of Computer Science, UCL
http://moodle.ucl.ac.uk/course/view.php?id=11547
GV01 - Mathematical Methods, Algorithms and Implementations: Linear Algebra Part II - Linear Transformations
2
Structure
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
3
Introduction
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
4
Why Transformations?
• In the first set of slides we laid out the linear spaces needed to do linear algebra
• This defines things like vectors, points, geometric objects and bases and the like
• Transformations are the things which actually dosomething useful with those spaces
5
Linear Transformations in Computer Graphics
• Complicated models are often composed of parts which must be:– Scaled– Rotated
– Translated
• Transformations are applied to complete each of these operations
6
Linear Transformations in Computer Graphics
• The transformations are often represented using homogeneous coordinates
• In 2D, these encode points and vectors as
• Operations such as translation and rotation are expressed using matrix multiplication
• It actually turns out that this representation is not a “hack” but is, in fact, a way to implement affine coordinates and affinetransformations
Linear Transformations in Face Recognition
7
Linear Transformations in Face Recognition
• We can’t simply take the absolute value of the differences in pixels– Very sensitive to slight changes in the image
• Normalised ratios between distances of feature points– Difficult to extend to multiple views– Very fragile
• Alternative is to use linear algebra approach– Simple– Robust– Performs automatic relevance detection
8
Constructing a Basis for the Images
• Each image Γi is treated as a single vector of dimension N2
• The training data of M images (for M people) is
• The mean image Ψ is simply the average,
9
Constructing a Basis for the Images
10
Constructing a Basis for the Images
• The difference between each training image and the mean image is
• A set of eigenfaces are computed from the set of difference vectors (how we’ll see later), giving the basis
11
The Basis or Eigenfaces
12
Recognising a Face
• The difference between the input image and the mean image is computed,
• This vector is written as a set of coordinates using E as the basis
where
• Therefore,
13
Recognising a Face
• The Euclidean distance between the sample coordinates and each eigenface is computed,
• The following logic is used:
14
Recognised Face
15
Unrecognised Face
16
Not a Face
17
18
Roadmap of the Material
LinearTransformations
Affine Maps
Transformations
General linear algebra concepts
Specific geometric applications
MatrixRepresentations
SampleTransformations
SampleTransformations
19
Transformations
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
20
Definition of a Transformation
• Let and be two sets with elements (which could be points, vectors, …)
• A function T from to , maps an input element into an output element
21
Representation of a Transformation
• The “input” set is the domain, and the “output” set the co-domain or range
• Several types of transformations exist
a b c d e
g h i j k
22
One-to-One Transformations
• Each element from the input set maps to a uniqueelement in the output set
• Note that all the input elements could all map to just a subset of
a b c
g h i j k
23
Onto Transformations
• All the element of map from at least one element of
a b c d e
g h i
24
Isomorphic Transformations
• All the elements of uniquely map to all the elements of • This is the same as T being both one-to-one and onto
a b c d e
g h i j k
25
Transformation Type Mini-Quiz
26
Transformation Type Mini-Quiz
27
Transformation Type Mini-Quiz
Transformation Type Mini-Quiz
28
Linear Combinations of Transformations
• It is possible to create linear combinations of transformations,
• The type of T(x) can be different from the type of any of the transformations Ti(x)
29
Mini-Quiz
• What kind of transformation is
where
and the domain and range are both the real numbers?
30
Positive and Negative Terms
Summed Solution
Fourier Series
33
34
Inverse Transformation
• An inverse transformation maps from the range to the domain
• The unique inverse exists for isomorphic transformations
a b c d e
g h i j k
a b c d e
g h i j k
35
Linear Transformations
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
36
Linear Transformations
• These are transformations which map from one vector space to another
• Formally, it is a map
with the following properties:
37
Illustrating the First Property
• Vectors which close a triangle before the transformation continue to do so afterwards
38
Illustrating the Second Property
• The relative lengths of vectors are preserved
Preservation of Linear Combinations
• These two properties mean that if
then
• Therefore, the effect of a linear transformation can be completely characterised by its effect on the basis vectors
39
Linear Transformation Mini-Quiz
• Let the (orthonormal) basis for (a Euclidean) vector space be
• Suppose
• Describe in words what this transformation does
40
Linear Transformation Mini-Quiz
• Now suppose the transformation is
• Describe in words what this transformation does
41
42
Affine Transformations
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
43
Affine Transformations (or Maps)
• Affine transformations transform, not surprisingly,affine spaces to affine spaces
• Affine combinations are preserved
where
44
Affine Transformations (or Maps)
• Affine transformations map points to points
• Therefore lines map to lines, planes to planes, etc.
45
Some Types of Affine Transformations
Original Translation Rotation
Reflection Scaling Shearing
46
Properties Preserved by Affine Maps
• Although it looks like affine maps can do completely arbitrary things, they must preserve three properties:
– Relative ratios– Addition of vector to points
– Parallelism
47
Preservation of Relative Ratios
• Recall that a point on a line can be written as the affinecombination
• By definition, affine maps preserve this affinecombination in the sense
48
Preservation of Relative Ratios
• In other words, the relative distances of R to P and R to Q remain the same
49
Preservation of Addition of Vectors to Points
• Affine maps preserve the property
• We prove this by first noting that
• Therefore, applying the transformation to both sides gives
Preservation of Addition of Vectors to Points
• Now,
50
51
Preservation of Parallelism
• Affine maps preserve the property that parallel lines remain parallel
52
Preservation of Parallelism
• To prove this, suppose we have two lines described by the affine combinations
• These lines are parallel if the vector connecting the defining points are proportional to one another, i.e.,
53
Preservation of Parallelism
• Applying the affine transformation to the first line gives:
• In other words, the transformed direction of the line is
54
Preservation of Parallelism
• Now, the affine transformation for line 2 is
• The transformed direction of line 2 is also
Affine Maps Mini Quiz
• What do affine maps do to lines orthogonal to one another?
55
Some Example Transformations
• To develop transformations, we have to ask the questions:– What happens to the points?– What happens to the vectors?
• Examples:– Translation
– Uniform scaling
56
Translation
57
Original Translation
58
Translation
• Translation causes the position of points to change by an amount
• The frame does not undergo any shearing or rotation and so the relative displacement between points do no change
Translation Mini-Quiz
• What’s the transformation of a vector
• What’s the transformation of the origin point
59
Uniform Scaling
60
Original Scaling
Uniform Scaling
• Uniform scaling about the origin causes the distances between all points to expand by the scale factor s
• Therefore,
61
Uniform Scaling
• What’s the transformation of the origin point
• What’s the transformation of an arbitrary point T(P)?
62
63
Moving from Coordinate-Free to Coordinates
• So far we’ve talked about spaces and transformations in a wholly coordinate free way– This views geometry as a set of abstract geometric objects– However, it’s not very concrete and you can’t implement it
• Now we are going to change gears and look at some of the mathematics of how to implement this– To do this, we have to develop coordinate representations of
points, vectors and transformations
64
Matrix Representations of Transformations
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
65
Matrix Representation of Vectors
• Recall that in a given a frame, a vector can be written as
• The coordinate axiom says that
• Therefore, the vector can also be written as
66
• This is equivalent to expanding the vector into the product of avector of coefficients with a matrix which encodes the frame,
• Therefore, the coordinate representation of the vector is
Matrix Representation of Vectors
Vector of coefficients
Coordinate frame
67
Matrix Representation of Points
• Similarly, a point can be written as the origin point plus a vector translation,
68
Matrix Representation of Points
• This can also be written as the product of a vector of coefficients with a matrix which encodes the frame,
• Therefore, the coordinate representation of a point is
Coordinate frame
Vector of coefficients
69
Matrix Representations of Transformations
• We can now express affine transformations in terms of matrix operations
• All the pertinent issues can be considered by looking at the problem of carrying out a change of basis
70
Matrix Representation of a Change of Basis
• The change of basis involves arbitrary affine transformations including translation, shearing and reflection
71
Affine Transformations and Coordinate Frames
• Formally, each frame is written as
72
Matrix Representation of Affine Transformations
• Applying an affine transformation to a point gives
• Because an affine transformation preserves affinecombinations,
73
Matrix Representation of Affine Transformations
• Therefore, the transformed point can be written using matrix multiplication in the new frame as
74
Matrix Representation of Affine Transformations
• However, we really want to express our transformed point directly as an updated set of coordinates in the new frame,
75
Affine Transformation of the Vectors
• First consider the effect of the new frame on the basis vectors
• This is simply a case of rewriting the vectors in terms of the new basis set,
76
Affine Transformation of the Origin Point
• The only transformation which can occur to the origin point is that it undergoes a translation,
• The transformation vector component can also be written in terms of the new basis and so
77
Matrix Representation of Affine Transformations
• Substituting, the matrix representation of the updated point is
• However, this still isn’t quite in the right form because each element of the second matrix is a sum of basis vector terms, not the basis terms individually
78
Matrix Representation of Affine Transformations
• The second matrix can be decomposed into the product of a matrix with the basis for the new frame,
79
Matrix Representation of Affine Transformations
• Therefore, the final transformation can be decomposed into as,
Coefficients of P in
Transformation matrix
80
Geometric Interpretation of T
• Expanding the transformation matrix,
Transformed basis vectors
of A
Transformed origin of A
81
Geometric Interpretation of T
• Therefore, all affine transformations can be written as
• This probably looks familiar from 2D and 3D homogeneous coordinates, but it works for anynumber of dimensions and any affine transformation
Summary of Matrix Representations
• If we write points and vectors using coordinates in a frame, we recover the familiar homogeneous coordinate representation of vectors and points
• All affine transformations can be written as matrices which act on these coordinates
• The transformation matrices contain two parts:– A transformation of the basis vector
– A translation of the origin point
82
83
Developing Some Sample Transformations
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
84
Deriving Some Specific Transformations
• We’ll derive the following types of transformations from an “affine” perspective (no pun intended):– Translation– Uniform scaling about an arbitrary point
– Orthographic projection– Perspective projection
85
Matrix Representation of Translation
• Recall that translation causes the position of points to change by an amount
• But vectors are left unchanged
86
Matrix Representation of Translation
• Now, any point can be written as
and its translated position is
Matrix Representation of Translation
• Therefore, we can model a translation as a translation of the origin point only,
87
88
Matrix Form of the Translation Transformation
• Therefore,
89
Matrix Form of the Translation Transformation
• To express the transformation as a matrix T, we must be able to move the translation term out of the basis and into the matrix itself
• This is achieved by noting that the translation vector itself can be written in terms of the basis,
90
Matrix Form of the Translation Transformation
• This gives us
91
Matrix Form of the Translation Transformation
• This can be written in the form,
Scaling Mini-Quiz
• What do you think the transformation matrix would look like for the non-uniform scaling operation about a point Q,
92
93
Matrix Form Mini-Quiz
• Suppose Q can be written as,
• Show that the affine transformation matrix is
Uniform Scaling About an Arbitrary Point
• Recall that the effect of a uniform scale about the origin is
• If we scale about an arbitrary point Q, then the term for translation of a point will change, but that of a vector will not
94
Uniform Scaling About an Arbitrary Point
• We know that
• Furthermore,
• Therefore,
95
Matrix Form
• The matrix form is
96
Orthographic Projection
• The orthogonal projection of points and vectors onto a plane
• For a 3D case with orthonormal vectors, this can be defined by a point and a normal vector
97
Orthographic Projection Mini-Quiz
98
Orthographic Projection of Vectors
• From the vector closure properties, we know that
• Since everything is projected onto the plane, we must have
99
Orthographic Projection of Vectors
• Recall that, from the definition of the inner product,
• Therefore,
100
Matrix Form of the Transformation
• We first have to rewrite
as a matrix
• In coordinate form,
101
Matrix Form of the Transformation
• Substituting,
102
Orthographic Projection of Points
• The transformation of T(P) has to put the point on the plane
• From the definition of an affine transformation and using the result we just computed for transforming vectors,
103
Orthographic Projection of Points
• Substituting
we get
104
Matrix Form of the Transformation
• The previous expression tells us how the points move around, but it is not written in terms of the origin and the displacement vectors
• By adding and subtracting the origin point, we can write this as
105
Matrix Form of the Transformation
• Given that
• The transformation of a point becomes
106
Matrix Form of the Transformation
• Therefore,
107
108
Perspective Projection
Perspective Projection (Side View)
109
Perspective Projection
• Perspective projection is not affine because it does notobey the condition
• The reason is that this form assumes that the way vectors are transformed is independent of the position of P in space
• Nonetheless, it ends up producing a “valid” affinecombination
110
Perspective Projection
111
Perspective Projection
112
Perspective Projection (Side View)
113
Computing the Projected Point
• Because the projected point lies on the line which passes through S and P, it must be possible to write the projected point as the affine combination
• We compute α by noting that the vector between Qand T(P) must be perpendicular to the plane normal,
114
Computing the Projected Point
• Substituting,
115
Computing the Projected Point
• Solving for α,
• Finally,
116
The Transformation Matrix
• It can be shown (=somebody else proved it!) that the final form of the transformation matrix is the somewhat scary-looking
• Its lack of affine-ness is shown by the fact that it does not look like matrices we saw earlier
117
Sample Transformations Summary
• The specific form of the transformation matrix can be deduced by looking at how the transformation affects points and vectors individually
• However, non affine transformations can generateaffine combinations as well
118
119
Composite Transformations
• Introduction
• Transformations
• Linear Transformations
• Affine Transformations
• Matrix Representations of Transformations
• Developing Some Sample Transformations
• Composite Transformations
120
Composite Transformations
• In many problems we can end up having to perform a large number of similar transformations
• One means of implementing this would be to implement each transformation separately
• However, a more efficient strategy is to build a transformation by composing it from other transformations
121
Composite Transformations
• Suppose we have two transformations,
• We can take the output of T and use it as the input for U
a b c
g h i
122
Composite Transformations
d e f
123
Composite Transformations
• As explained earlier, sometimes its highly desirable to use composition to assemble a transformation from various simple transformations
• This is equivalent to concatenating a series of affinetransformations one after another
• Consider the sequence
124
Matrix Interpretation of Composition
• Cascading the transformations together,
Coefficients of P in A
Transformation matrix
Transformation matrix
Affine Property of Composite Transformations
• Recall that an affine transformation can be written as
• A second affine transformation can be written as
125
Affine Property of Composite Transformations
• The combined transformation matrix is
• This is obviously affine again
126
127
Composite Transformation Mini-Quiz
• Use composite transformations to construct the transformation matrix for uniform scaling about a point Q
128
Simple Scaling About A Non-Origin Point
• The composite transformation which achieves this is:
Simple Scaling About A Non-Origin Point
129
130
Order Matters
• Because matrix multiplication is non-commutative, the order in which we carry out these operations is important
• If we reverse the order of translations, the resulting transformation is
Scaling About A Non-Origin Point
131
Rot Trans vs. Trans Rot
132
133
Inverse Transformation
• Sometimes we want to invert a transformation,
where I(.) is the identity transformation
• In matrix form, we need to compute matrix inverses
• This leads us to systems of linear equations
Summary
• Composite transformations let us cascade multiple transformations together and can be used tosynthesise complicated effects from simple components
• Affine transformations remain affine
• However, the order in which we apply the transformations do matter
• We can define inverse transformations but, to do that, we need to be able to invert matrices
134