Sunteți pe pagina 1din 27

Transformations

Transformations
 2D-to-2D (image-to-image)
 3D-to-3D (world-to-world)
 3D-to-2D (camera model)
 2D-to-3D (shape from X)
 Shape from Stereo
 Shape from Shading
 Shape from Texture
 Structure from Motion
Points
 World points are 3-Dimensional
P = [X, Y, Z]T

Or in homogeneous coordinates
P = [hX, hY, hZ, h]T
 Image points are 2-Dimensional
p = [x, y]T

Or in homogeneous coordinates
p = [hx, hy, h]T

Points
y
y

x
z (1,5,2)T or
(10, 50, 20, 10)T
(5, 6)T or
x
(10, 12, 2)T
Transformations
 To define a point, we have to define a
coordinate system
 Transformations are functions that
convert points from one coordinate
system to another
 Translation, Rotation, Shear, Scaling…

2-D Transformations

Scaling
Original
Translation

Rotation Shear
2D Transformation
 Definition: A mapping from one 2D
coordinate system to another
 Also called
 spatial transformation,
 geometric transformation,
 warp
 Image Registration: Process of transforming
two images so that same features overlap

Example Application:
Image Registration

Reference
Image
Mission
Images

Registration = Computing Transformation


2D Transformations
 Basic operation of all 2D
transformations is simple
Point to be transformed: [x, y ]
Point after transformation: [x’, y’ ]

 a1 a2   x   a1 x a2 y   x'
a    =  = 
 3 a4   y  a3 x a4 y   y '
Position Position
Transformation after
before
Matrix transformation
transformation

Example
(0,0) (0,a) (0,0) (0,a)
Apply
0.5 0 
 0 0.5
 
(a,0) (a,a) (a,0) (a,a)

Original Transformed

0.5 0  0 0 0.5 0  a  0.5a 


 0 0.5 0 = 0  0 0.5 a  = 0.5a 
         
0.5 0  a  0.5a  0.5 0  0.5a  0.25a 
 0 0.5 0  =  0   0 0.5 0.5a  = 0.25a 
         
2D Transformations

1.5 0 
 0 0.5 = ?
 
In general, scaling transformation is given by

sx 0
0 s y 

2D Transformations 1 1
0 1 = ?
 
(0,0) (0,1)
(0,0) (0,1)

(1,0) (1,1)
(1,0) (1,1)
Original
Transformed

(2,1)
Shear in x-direction
1 e  x   x + ey 
0 1  y  =  y 
    

 x-coordinate moves with an amount


proportional to the y-coordinate

Shear in y-direction
1 0  x   x 
e 1  y  = ex + y 
    

 y-coordinate moves with an amount


proportional to the x-coordinate
2D Transformations

 − 1 0 1 0 
 0 1 = ? 0 − 1 = ?
   
− 1 0 
 0 − 1 = ?
  Reflection is negative scaling

Rotation
y
(x2 y2)

(x1 y1)
θ

 Task: Relate (x2 y2) to (x1 y1)


x2 = R cos(θ + ϕ )
Rotation y2 = R sin(θ + ϕ )
x2 = R cosθ cos ϕ − R sin θ sin ϕ
y
y2 = R sin θ cos ϕ + R cosθ sin ϕ
(x2 y2)

R
x2 = x1 cosθ − y1 sin θ
(x1 y1)
y2 = x1 sin θ + y1 cosθ
R
θ
y1 = R sin ϕ
ϕ
 x2  cos θ − sin θ   x1 
x  y  =  sin θ cos θ   y1 
 2 
x1 = R cos ϕ
R
R is rotation by θ counterclockwise about origin

Rotation
 Rotation Matrix has some special
properties
 Each row/column has norm of 1 [prove]
 Each row/column is orthogonal to the
other [prove]
 So Rotation matrix is an orthonormal
matrix
2D Translation
 Point in 2D given by (x1 y1)
 Translated by (dx dy)

x2 = x1 + dx
y 2 = y1 + d y

Translation
 In matrix form

 x2  1 0 d x   x1 
 y  = 0 1 d   y 
 2  y  1

 1  0 0 1   1 

We could not have written T without using


homogeneous coordinates
Basic 2D Transformations

cosθ − sin θ 0 sx 0 0


 sin θ 0 0
 cosθ
 sy 0
 0 0 1
 0 0 1
1 0 d x  1 ex 0 1 0 0
0 1 d  0 1
 y
 0 e
 y 1 0
0 0 1  0 0 1  0 0 1

Inverse Scaling

1 
sx 0 0 s 0 0
 x 
S =  0 sy 0 S −1 =  0
1
0
 sy 
 0 0 1 0 0 1
 
 

S S-1 = I
Inverse Translation

1 0 d x  1 0 − d x 
T = 0 1 d y  T −1 = 0 1 − d y 
0 0 1  0 0 1 

T T-1 = I

Inverse Rotation

cosθ − sin θ 0  cosθ sin θ 0


R =  sin θ cosθ 0 R −1 = − sin θ cosθ 0
 0 0 1  0 0 1

RR-1 = I
Rotation about an Arbitrary
Point
 The rotation matrix that we have
derived is for rotations about the origin
 We may want to rotate about some
other point
 Solution?
 Translate point of rotation to origin,
rotate using normal rotation matrix,
translate back

Rotation about an Arbitrary


Point
Concatenation or Composition
of Transformations
 Suppose we first want to scale, then rotate
x’ = Sx
x’’ = Rx’
= R(Sx)
= (RS) x
 So two transformations can be represented
by a single transformation matrix
M = RS
 Important: read from right-side to get order
of application of transformations

Concatenation or Composition
of Transformations
 We can concatenate a large number of
transformations into a single
transformation
 p2 = T[dx dy] S[s s]Rθ p1
 Rules of matrix multiplication apply
 If we do not use homogeneous
coordinates, what might be the problem
here?
Example
S= sx 0
0 sy
R= cosθ -sinθ
sinθ cosθ
Then
RS = sx cosθ -sy sinθ
sx sinθ sy cosθ
SR = sx cosθ -sx sinθ
sy sinθ sy cosθ

Order of Transformations
 In general AB ≠ BA
 However, in specific cases, this might
hold true
 In the previous example, if sx = sy,
then order of transformations does not
matter
Order of Transformations

Scaled Rotated

Original

Rotated Scaled
Original

Order of Transformations

Scaled Rotated

Original

Rotated Scaled
Original
Order of Transformations
 Rotation/Scaling/Shear, followed by
Translation
1 0 b1   a1 a2 0  a1 a2 b1 
0 1 b   a a4 0 = a3 a4 b2 
 2  3

0 0 1   0 0 1  0 0 1 
 Translation, followed by
Rotation/Scaling/Shear
 a1 a2 0 1 0 b1   a1 a2 a1b1 + a2b2 
a a4 0 0 1 b2  = a3 a4 a3b1 + a4b2 
 3
 0 0 1 0 0 1   0 0 1 

Affine Transformation
 Consider again the transformation
matrix of Rotation/Scaling/Shear,
followed by Translation
 a1 a2 b1 
a a4 b2 
 3
 0 0 1 

 This is known as the affine


transformation
Affine Transformation
 Encodes rotation, scaling, translation and
shear

x2 = a1 x1 + a2 y1 + b1
y2 = a3 x1 + a4 y1 + b2
 6 parameters
 Linear transformation
 Parallel lines are preserved [proof ?]

Affine Transformation

Ref: Steve Mann & Rosalind W. Picard, “Video Orbits of the Projective
Group: A simple approach to featureless estimation of parameters”, IEEE
Trans. on Image Processing, Vol. 6, No. 9, September 1997
Affine Transformation
 If [a1 … a4] are restricted to pure rotation
matrix, then this case is called rigid-body or
euclidean transformation

Recovering Best Affine


Transformation
 Given two images with unknown
transformation between them…

 Compute the values for [a1 … a6]


Recovering Best Affine
Transformation
 Suppose we are given some
correspondences

Recovering Best Affine


Transformation

Image 1 Image 2 Overlap of points


after recovering
the transformation
We can try to find the set of parameters in which
the error is minimum
Recovering Best Affine
Transformation
 Least Squares Error Solution
 Is the solution (i.e. set of parameters

a1 … a6) such that the sum of the


square of error in each corresponding
point is as minimum as possible
 No other set of parameters exists that

may have a lower error

Least Squares Error Solution


 x*j   a1 a2 a3   x' j 
 * 
 y j  =  a4 a5 a6   y ' j 
  (x , y )
* *

 1   0
j j

  0 1   1  (x , y
j j

n
E (a1 , a2 , a3 , a4 , a5 , a6 ) = ∑ ( x*j − x j ) 2 + ( y *j − y j ) 2
j =1

n
(
E (a) = ∑ (a1 x' j + a2 y ' j + a3 − x j ) 2 + (a4 x' j + a5 y ' j + a6 − y j ) 2
j =1
)
Least Squares Error Solution
n
E (a) = ∑ ((a x + a y + a − x ) + (a x + a y + a − y ) )
1 j 2 j 3
' 2
j 4 j 5 j 6
' 2
j
j =1
 Minimize E w.r.t. a

 Compute ∂E ∂a , put equal to zero, solve simultaneously


i

 ∑ x 2j ∑x y ∑x j j j 0 0 0   ∑ x j x 'j 
 j j j   j 
 x y 0   a1   ∑ y j x 'j 
∑ ∑y ∑y 2
0 0
j
j j
j
j
j
j
   j 
   a2   ' 
 ∑ xj ∑ y ∑1 j 0 0 0 
 a3   ∑
xj 
 j j j
  =  j

 0 0 0 ∑x ∑x y 2
j j j ∑j x j  a4  ∑j x j y 'j 
 j j  a   
 0 0 0 ∑x y ∑y j j
2
j ∑j y j  a5  ∑j y j y 'j 
 j j   6   
 0

0 0 ∑x ∑y j j ∑j 
1   ∑ j 
 j
y ' 

j j  

S-ar putea să vă placă și