Lec4 CvITU02 Warping
Lec4 CvITU02 Warping
Lec4 CvITU02 Warping
Transformation 2
Instructor: Mohsen Ali
2-D Transformations
Scaling
Original
Translation
Shear
Affine
Rotation
Projective
Basic 2D Transformations
cos
sin
1 0 d x
0 1 d
y
0 0 1
sin
cos
0
0
0
1
1 ex
0 1
0 0
sx
0
0
0
0
1
0
sy
0
1
e
y
0
0
0
1
0 0
1 0
0 1
Order of Transformations
Scaled
Rotated
Rotated
Scaled
Original
Original
Hierarchy of 2D Transformations
Length Ratios
Length Ratios
Length Cross-Ratios
Recovering
Best Affine Transformation
Input: we are given some correspondences
Output: Compute a1 a6 which relate the images
Recovering
Affine
Transformation
Input: weBest
are given
some correspondences
Output: Compute a1 a6 which relate the images
a1
a2
a3
a4
a5
a6
a7
a8
a9
This is an optimization problem Find the best set of parameters, given the input data
Recovering
Affine
Transformation
Input: weBest
are given
some correspondences
Output: Compute a1 a6 which relate the images
a1
a2
a3
a4
a5
a6
This is an optimization problem Find the best set of parameters, given the input data
Six Unknowns
' 2
j
' 2
+
a
y
+
a
y
j
j)
5 j
6
j =1
Minimize E w.r.t. a
E
Compute a , put equal to zero, solve
simultaneously
i
x 2j
j
x y
j j
xj
j
0
x y x
y y
y 1
j
2
j
x x y
x y y
x
y
2
j
2
j
x j x 'j
0
j
'
0
yjxj
1
j
a
2
0 x 'j
a3
= j
'
x
x
y
a
j j 4 j j j
a
'
5
y
y
y
j j a j j j
6
'
j 1
j y j
Pseudo inverse
For an over-constrained linear system
Ax = b
A has more rows than columns
Multiply by AT on both sides
ATAx = ATb
ATA is a square matrix of as many rows as x
We can take its inverse
x = (ATA)-1ATb
x1
0
x2
0
x3
0
x
4
0
y1
0
y2
0
1 0
0 x1
1 0
0 x2
0
y1
0
y2
y3
0
y4
0
1 0
0 x3
1 0
0 x4
0
y3
0
y4
0
x1 '
1 a1 y1 '
0 a2 x2 '
1 a3 y2 '
=
0 a4 x3 '
1 a5
y3 '
0 a6 x4 '
1
y4 '
x
2D Affine Warping
Warping
Inputs:
Image X
Affine Transformation A = [a1 a2 b1 a3 a4 b2]T
Output:
Generate X such that X = AX
Obvious Process:
For each pixel in X
Apply transformation
At that location in X, put the same color as at the original location in X
Problems?
Warping
Reverse Transformation
Interpolation
In 1D
3
Use y=mx+c
m: slope of the line
c: intersect
m = 1, c = -2
4
4.3 ?
2D Bilinear Interpolation
Four nearest points of (x, y)
(x, y )
(x, y )
( x, y )
where
x = int( x)
y = int( y )
x = x +1
y = y +1
(x, y )
(x, y )
Bilinear Interpolation
f ' ( x, y ) = x y f ( x, y ) + x y f ( x, y ) + x y f ( x, y ) + x y f ( x, y )
x = x x
y = y y
x = x x
y = y y
(x, y )
(x, y )
x
(x, y )
(x, y )
Warping
To apply Translation T of [0,1]
Calculate inv(T)
Translation T [0, 1]
(0,0)
(0,1)
(0,0)
(0,1)
(1,0)
(1,1)
(1,0)
(1,1)
I1
I2
Warping
What if the Translation is [0, 0.7]
Translation T [0, 0.7]
To apply Translation T of [0,0.7]
Calculate inv(T), [0, -0.7]
(0,0)
(0,1)
(0,0)
(0,1)
(1,0)
(1,1)
(1,0)
(1,1)
I1
I2
Bilinear Interpolation
Also applied separately
3D Transformations
3D Translation
Point in 3D given by (X1 Y1 Z1)
Translated by (dx dy dz)
X2 = X1 + dx
Y2 = Y1 + dy
Z2 = Z1 + dz
Translation
In matrix form
X 2 1
Y 0
2=
Z 2 0
1 0
0 0 dx X 1
1 0 dy Y1
0 1 dz Z1
0 0 1 1
T
Inverse Transformation
1
0
T=
0
0 0 dx
1 0 dy
0 1 dz
0 0 1
T T-1 = I
1
0
T 1 =
0
0 0 dx
1 0 dy
0 1 dz
0 0
1
Scaling
Point in 3D given by (X1 Y1 Z1)
Scaled by (Sx Sy Sz)
X2 = X1 * Sx
Y2 = Y1 * Sy
Z2 = Z1 * Sz
Scaling
In matrix form
X 2 Sx 0 0 0 X 1
Y 0 Sy 0 0 Y
2=
1
Z 2 0 0 Sz 0 Z1
1 0 0 0 1 1
Inverse Transformation
Sx 0 0 0
0 Sy 0 0
S=
0 0 Sz 0
0
0
0
1
S S-1 = I
1
Sx
0
1
S =
0
0
1
Sy
0
0
1
Sz
0
0
1
Shearing
What will these do?
1
0
e 0 0
1 0 0
0 1 0
0 0 1
1
0
0 e 0
1 0 0
0 1 0
0 0 1
1
0
e 0 1
1 0 0 e
0 1 0 0
0 0 1 0
0 0
1 0 0
0 1 0
0 0 1
3D Rotation
(x2 y2 z2)
X ' cos
Y ' sin
=
Z ' 0
1 0
sin
cos
0
0
0 0 X
0 0 Y
1 0 Z
0 1 1
(x1 y1 z1)
Rotation
Y
Positive rotation is
counterclockwise when looking
down the axis of rotation
towards origin
(x2 y2 z2)
(x1 y1 z1)
Rotation about Z
X
Z
x Rotation about Y
Rotation about X
y
x
z
y
Rotation about Z
cos
sin
sin
cos
0
0
0
0
1
0
0
0
0
0
1
0 cos
0 sin
0
0
0
sin
cos
0
Rotation about Y
0
0
0
cos
0
sin
0 sin
1
0
0 cos
0
0
0
0
0
Concatenation of Rotations
R = RZ RY RX
r12
r22
r32
r13 X Tx
r23 Y + Ty
r33 Z Tz
or
X ' r11
Y ' r
= 21
Z ' r31
1 0
r12
r22
r32
0
r13 TX X
r23 Ty Y
r33 TZ Z
0 1 1
r12
r22
r32
r13
r23
r33
1 i=k
j =1
j =1
39
r13 r11 1
r23 r12 = ?0
r33 r13 0
r11 r12
r
r
21 22
r31 r32
r13 r31 0
r23 r32 = 0
r33 r33 1
r11 r12
r
r
21 22
r31 r32
r13 r21 0
r23 r22 = 1
r33 r23 0
sin
cos
0
0
0 0
0 0
1 0
0 1
0
1
0 cos
0 sin
0
0
0
sin
cos
0
0
0
0
cos
0
sin
0 sin
1
0 cos
0
0
0
0
Hierarchy of 3D Transformations
Factorizing Transformations
a2
a4
0
b1 1 0 b1 a1
b2 = 0 1 b2 a3
1 0 0 1 0
a2
a4
0
0
0
1
a2
a4
A=
T
(Implication?)
Example
http://en.wikipedia.org/wiki/Singular_value_decomposition
0.49
0.89
0
>> U * S * V'
-0.62384
0.78156
S=
ans =
0.95
0.23
0.46
0.02
1
0.49
0.89
1.2904
0
0 0.56789
V=
-0.68658
-0.72705
-0.72705
0.68658
Interpretation in
terms of angles?
Try it as an exercise
Scaling
Shear
Rotation
Translation
Inverse Transformations
Rotation about an arbitrary point
Concatenation of transformations
Order of transformations
Factorization of Transformations
Displacement Models
Rigid / Euclidean
Similarity
Affine
Projective
Billinear, biquadratic etc
Image Warping
3D Transformations
Rotations about Principal Axes
Rotations about Arbitrary Axes