Transcript ppt

Image Warping (Szeliski Sec 2.1.2)
http://www.jeffrey-martin.com
CS194: Image Manipulation & Computational Photography
Alexei Efros, UC Berkeley, Fall 2014
Some slides from Steve Seitz
Image Transformations
image filtering: change range of image
g(x) = T(f(x))
f
f
T
x
x
image warping: change domain of image
g(x) = f(T(x))
f
f
T
x
x
Image Transformations
image filtering: change range of image
g(x) = T(f(x))
f
g
T
image warping: change domain of image
g(x) = f(T(x))
f
g
T
Parametric (global) warping
Examples of parametric warps:
translation
affine
rotation
perspective
aspect
cylindrical
Parametric (global) warping
T
p’ = (x’,y’)
p = (x,y)
Transformation T is a coordinate-changing machine:
p’ = T(p)
What does it mean that T is global?
• Is the same for any point p
• can be described by just a few numbers (parameters)
Let’s represent a linear T as a matrix:
p’ = Mp
 x'
x
 y '  M  y 
 
 
Scaling
Scaling a coordinate means multiplying each of its components by
a scalar
Uniform scaling means this scalar is the same for all components:
2
Scaling
Non-uniform scaling: different scalars per component:
X  2,
Y  0.5
Scaling
Scaling operation:
x '  ax
y '  by
Or, in matrix form:
 x '  a 0  x 
 y '   0 b   y 
  
 
scaling matrix S
What’s inverse of S?
2-D Rotation
(x’, y’)
(x, y)

x’ = x cos() - y sin()
y’ = x sin() + y cos()
2-D Rotation
(x’, y’)
(x, y)

f
x = r cos (f)
y = r sin (f)
x’ = r cos (f + )
y’ = r sin (f + )
Trig Identity…
x’ = r cos(f) cos() – r sin(f) sin()
y’ = r sin(f) cos() + r cos(f) sin()
Substitute…
x’ = x cos() - y sin()
y’ = x sin() + y cos()
2-D Rotation
This is easy to capture in matrix form:
 x '  cos   sin    x 
 y '   sin   cos    y 
  
 
R
Even though sin() and cos() are nonlinear functions of ,
• x’ is a linear combination of x and y
• y’ is a linear combination of x and y
What is the inverse transformation?
• Rotation by –
• For rotation matrices
R 1  RT
2x2 Matrices
What types of transformations can be
represented with a 2x2 matrix?
2D Identity?
x'  x
y'  y
 x'  1 0  x 
 y' 0 1  y 
2D Scale around (0,0)?
x'  s x * x
y'  s y * y
 x '  s x
 y'   0
  
0  x
s y   y 
2x2 Matrices
What types of transformations can be
represented with a 2x2 matrix?
2D Rotate around (0,0)?
x'  cos  * x  sin  * y
y '  sin  * x  cos  * y
 x ' cos   sin   x 
 y '   sin  cos    y 
  
 
2D Shear?
x '  x  shx * y
y '  sh y * x  y
 x '  1
 y'   sh
   y
shx   x 
1   y 
2x2 Matrices
What types of transformations can be
represented with a 2x2 matrix?
2D Mirror about Y axis?
x'   x
y'  y
 x '     1 0  x 
 y '  0 1  y 
2D Mirror over (0,0)?
x'   x
y'   y
 x'   1 0   x 
 y '  0  1  y 
2x2 Matrices
What types of transformations can be
represented with a 2x2 matrix?
2D Translation?
x'  x  t x
y'  y  t y
NO!
Only linear 2D transformations
can be represented with a 2x2 matrix
All 2D Linear Transformations
Linear transformations are combinations of …
•
•
•
•
Scale,
Rotation,
Shear, and
Mirror
 x' a b   x 
 y '   c d   y 
  
 
Properties of linear transformations:
•
•
•
•
•
Origin maps to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved
Closed under composition
 x'   a b   e
 y'  c d   g
f  i
h  k
j x
l   y 
Consider a different Basis
j =(0,1)
v =(vx,vy)
p
q
u=(ux,uy)
i =(1,0)
q=4i+3j = (4,3)
p=4u+3v
Linear Transformations as Change of Basis
v =(vx,vy)
j =(0,1)
puv
pij
u=(ux,uy)
i =(1,0)
puv = (4,3)
px=4ux+3vx
py=4uy+3vy
pij = 4u+3v
ux
pij  
u y
v x   4  u x
   
v y  3 u y
Any linear transformation is a basis!!!
vx 
puv
vy 
What’s the inverse transform?
j =(0,1)
v =(vx,vy)
pij
puv
u=(ux,uy)
i =(1,0)
pij = (5,4) = pxu + pyv
puv 
ux

u y
-1
vx 

vy 
 5  u x
   u
4  y
puv = (px,py) = ?
-1
vx 
 pij
vy 
• How can we change from any basis to any basis?
• What if the basis are orthogonal?
Projection onto orthogonal basis
j =(0,1)
v =(vx,vy)
pij
puv
u=(ux,uy)
i =(1,0)
pij = (5,4)
puv 
puv = (u·pij, v·pij)
ux

v y
ux 

vy 
 5  u x
   v
4  x
uy 
ij
p

vy 
Homogeneous Coordinates
Q: How can we represent translation as a 3x3
matrix?
x'  x  t x
y'  y  t y
Homogeneous Coordinates
Homogeneous coordinates
• represent coordinates in 2
dimensions with a 3-vector
 x
 x  homogeneous coords  
 y   y 
 
 1 
Homogeneous Coordinates
Add a 3rd coordinate to every 2D point
• (x, y, w) represents a point at location (x/w, y/w)
• (x, y, 0) represents a point at infinity
• (0, 0, 0) is not allowed
y
2
(2,1,1) or (4,2,2) or (6,3,3)
1
Convenient
coordinate system to
represent many
useful
transformations
1
2
x
Homogeneous Coordinates
Q: How can we represent translation as a 3x3
matrix?
x'  x  t x
y'  y  t y
A: Using the rightmost column:
1 0 t x 


Translation  0 1 t y 
0 0 1 


Translation
Example of translation
Homogeneous Coordinates
 x '  1 0 t x   x   x  t x 
 y '  0 1 t   y    y  t 
y  
y
  

 1  0 0 1   1   1 
tx = 2
ty = 1
Basic 2D Transformations
Basic 2D transformations as 3x3 matrices
 x '  s x
 y '   0
  
 1   0
 x '  1 0 t x   x 
 y '  0 1 t   y 
y  
  
 1  0 0 1   1 
Translate
 x' cos 
 y '   sin 
  
 1   0
 sin 
cos 
0
Rotate
0  x 
0  y 
1  1 
0
sy
0
Scale
0  x 
0  y 
1  1 
 x '  1
 y '   sh
   y
 1   0
shx
1
0
Shear
0  x 
0  y 
1  1 
Matrix Composition
Transformations can be combined by
matrix multiplication
 x'   1 0 tx cos   sin  0  sx 0 0   x 
 y '    0 1 ty  sin  cos  0  0 sy 0   y 
  
 w'  0 0 1   0



0
1
  0 0 1   w

p’ =
T(tx,ty)
R()
S(sx,sy)
p
Affine Transformations
 x'  a b
Affine transformations are combinations of …   
y'  d e
• Linear transformations, and
 w  0 0
  
• Translations
Properties of affine transformations:
•
•
•
•
•
•
Origin does not necessarily map to origin
Lines map to lines
Parallel lines remain parallel
Ratios are preserved
Closed under composition
Models change of basis
Will the last coordinate w always be 1?
c  x 
f  y 
1   w
Projective Transformations
Projective transformations …
• Affine transformations, and
• Projective warps
 x'   a
 y '  d
 w'  g
  
Properties of projective transformations:
•
•
•
•
•
•
Origin does not necessarily map to origin
Lines map to lines
Parallel lines do not necessarily remain parallel
Ratios are not preserved
Closed under composition
Models change of basis
b
e
h
c  x 
f  y 
i   w
2D image transformations
These transformations are a nested set of groups
• Closed under composition and inverse is a member