Академический Документы
Профессиональный Документы
Культура Документы
Transformations
Part One
2D Transformations
Spatial Coordinates
(x,y) are mapped to new coords (u,v)
pixels of source image -> pixels of destination
image
Types of 2D Transformations
Affine
Scales
Translations
Rotations
Shears
Projective
Projections
Homographies or Collineations
1
Scale and Translation
Scale
u = s_x * x
v = s_y * y
Translation
u = x + t_x
v = y + t_y
Shear
u = x + Sh_x * y
v = y + Sh_y * x
2
Shear
Consider Sh_x only (Sh_y=0)
u = x + Sh_x*y;
v = y;
Homogenous Coords
Translation is just an addition
We can make it a function of
multiplication by using homogenous
coords
Homogenous coords are
equivalent up to a scale factor
p p p p
u 1 0 tx x wu 1 0 tx wx
v = 0 1 ty y wv = 0 1 ty wy
1 0 0 1 1 w 0 0 1 w
3
Homogenous Coordinates
Transform works on scale (w)
*w
w=1
Matrix Notation
p Affine p
u a b c x
v d e f y
1 = 0 0 1 1
4
Matrix notation of transforms
Translation Scale
p p p p
u 1 0 tx x u Sx 0 0 x
v = 0 1 ty y v = 0 Sy 0 y
1 0 0 1 1 1 0 0 1 1
Rotation Shear
p p p p
u cos -sin 0 x u 1 Shx 0 x
v = sin cos 0 y v = Shy 1 0 y
1 0 0 1 1 1 0 0 1 1
Concatenation
You can concatenate several
transforms into one matrix
A = R S Sh T
rotate scale shear translate
5
Affine Transformations
Affine is a linear mapping plus a translation:
A function f(x) is linear iff
f(x+y) = f(x) + f(y)
a*f(x) = f(a*x)
6
Preserves
Source Destination
Source Destination
6 degrees of freedom
u a b c X
v = d e f Y
1 0 0 1 1
1 1
7
Equations to solve for
Affine Transform
u1 = a*x1 + b*y1 + c
u2 = a*x2 + b*y2 + c
u3 = a*x3 + b*y3 + c
v1 = d*x1 + e*y1 + f
v2 = d*x2 + e*y2 + f
v3 = d*x3 + e*y3 + f
More commonly
You can build an Affine transform by
concatenating several transforms together
translate to the origin
Rotate by 20 degrees
translate back from the origin
scale by 5
8
Example
9
Affine Transform Limitation
Can map a triangle in source space
To a triangle in destination space
(or two parallelograms)
Projective Transform
Projective transform can transform
general quadrilaterals between source
and destination space
10
Projective transform uses
homogenous coords
su a b c x
sv = d e f y
s g h 1 1
Projective Transforms
Very common in computer graphics
Texture mapping a 3D polygon
polygon has been projected onto a plane
3D polygon
Texture map
3D perspective
projection
2D polygon
11
Projective Transform
Does not preserve length, equispacing
Does
Map lines to lines
Preserve incidents
Preserve cross ratio
Cross Ratio
Given 4 points on a line in source space and
destination space
D
C
B
A B C D
A
|AC||AD| |AC||AD|
|BC||BD|
= |BC||BD|
Cross Ratio
12
Solving for a Projective Transform
8 degrees of freedom
su a b c x
sv = d e f y We need 4 point correspondences
s g h 1 1 between source and destination image
source destination
su = ax + by + c
Remember, with projective transform
sv = dx + ey + f
destination points are:
s = gx + hy + 1
dest_u = su/s
dest_v = sv/s
u =su = ax + by + c (gx+hy+1)u = ax + by + c (. . . )
s gx + hy +1 gx + hy +1
gxu + hyu + u = ax + by + c
v =sv = dx + ey + f
s gx + hy +1
u = ax + by + c gxu hyu
13
8x8 System of Equations
x0 y0 1 0 0 0 -x0u0 -y0u0 a u0
x1 y1 1 0 0 0 -x1u1 -y1u1 b u1
x2 y2 1 0 0 0 -x2u2 -y2u2 c u2
d
= u3
x3 y3 1 0 0 0 -x3u3 -y3u3
0 0 0 x0 y0 1 -x0v0 -y0v0 e v0
0 0 0 x1 y1 1 -x1v1 -y1v1 f v1
0 0 x2 y2 1 -x2v2 -y2v2 g v2
0 0 0 x3 y3 1 -x3v3 -y3v3 h v3
14
Properties of Transforms
euclidean similarity affine projective
Transformation
translation X X X X
rotation X X X X
uniform scale X X X
non-uniform scale X X
shear X X
projection X
combination (w/ projection) X
Properties of Transforms
euclidean similarity affine projective
Invariant
length X
angle X X
ratio of lengths X X
parallelism X X X
incident X X X X
cross ratio X X X X
15
Transforming an Image
f(x,y)
Y
16
Image Coords vs. Cartesian Coords
origin
x
f(x,y)
Y
17
Cartesian space to image space
From Cartesian space to Image Space
find (x_min, xmax)
find (y_min, ymax)
Converting to an Image
origin
x
18
The transformed image
19
Mapping Pixels
4
1
3 4 3
Source Destination
Image [u,v,s]T = A [x,y,1]T Image
Transform
Forward Mapping
Draw backs
Source pixels do not map directly to a
single pixel in the destination space
20
Reverse Mapping
Reverse Mapping
1 (0,0) (0,N)
1 2 2
1 2
4
3 2 1
3 4 3 3 4
(0,M) (M,N)
4
black
[x,y,s]T = A-1[u,v,1]T
Inverse Mapping
Advantages
We assign an intensity to each pixel in
the destination (no holes)
Affine/projective transforms have
inverses (not a problem)
just reverse direction of the point
correspondences
We still dont have pixel to pixel
mapping
21
Sampling the source
22
Mapping
Source
2 x 2 pixels
Mapping
Source
2 x 2 pixels Small change results in big difference
23
Try different sampling
Source What if we assign an intensity
2 x 2 pixels to each vertex and then average?
3 4
1 2 3 4
New Sample =
Sampling Example
Source Move the destination slightly.
2 x 2 pixels
3 4
1 2 3 4
New Sample =
24
No Difference
Source Source
2 x 2 pixels 2 x 2 pixels
2
1 2
1 3
3 4
4
25
Try different Sampling
Source
2 x 2 pixels
1 2 What if we sampled
a larger area?
3
4
26
Common Sampling Approaches
Nearest Neighbor
1 Sample
Take closest pixel value
Bi-linear Interpolation
2x2 (4) Samples
Interpolate from these samples
Slower
Bi-Cubic
4x4 (8) samples
Construct a new sample using a non-linear interpolation
Slower
Bi-linear Interpolation
Bi-Cubic
27
Common Sampling Approaches
What do these approaches mean?
Nearest Neighbor
Bi-linear Interpolation
Bi-Cubic
f(x)
28