You are on page 1of 34

Image Warping

http://www.jeffrey-martin.com

Some slides from Steve Seitz

15-463: Computational Photography Alexei Efros, CMU, Fall 2005

Image Warping
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 Warping
image filtering: change range of image g(x) = h(T(x))
f g

image warping: change domain of image g(x) = f(T(x))


f g

Parametric (global) warping


Examples of parametric warps:

translation

rotation

aspect

affine

perspective

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)

Lets represent T as a matrix: p = M*p

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:

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 Whats inverse of S?

2-D Rotation

(x, y) (x, y)

x = x cos() - y sin() y = x sin() + y cos()

2-D Rotation
x = r cos () y = r sin () x = r cos ( + ) y = r sin ( + ) Trig Identity x = r cos() cos() r sin() sin() y = r sin() sin() + r cos() cos() Substitute x = x cos() - y sin() y = x sin() + y cos()

(x, y) (x, y)

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, det(R) = 1 so

R 1 = R T

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
x ' s x y ' = 0 0 x sy y

2D Scale around (0,0)?

x' = s x * x y' = 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 ' = shy * 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 Origin maps to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition

x' a b x y ' = c d y

Properties of linear transformations:

x' = a b e y ' c d g

f i h k

j x l y

Linear Transformations as Change of Basis


j =(0,1) v =(vx,vy) p

u=(ux,uy) i =(1,0) p=4i+3j = (4,3) p=4u+3v px=4ux+3vx py=4uy+3vy

ux p' = u y

v x 4 u x = v y 3 u y

vx p vy

Any linear transformation is a basis!!!


Whats the inverse transform? How can we change from any basis to any basis? What if the basis are orthogonal?

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 homogeneou scoords y y 1

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 1 1 0 0 1

tx = 2 ty = 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 1

(2,1,1) or (4,2,2) or (6,3,3)


1 2

Convenient coordinate system to represent many useful transformations

Basic 2D Transformations
Basic 2D transformations as 3x3 matrices

x' 1 0 t x x y ' = 0 1 t y y 1 0 0 1 1

x ' s x y ' = 0 0 1

0 sy 0

0 x y 0 1 1

Translate
x' cos y ' = sin 1 0 sin cos 0 0 x y 0 1 1

Scale
x ' 1 y ' = sh y 0 1 shx 1 0 0 x y 0 1 1

Rotate

Shear

Affine Transformations
x' a b Affine transformations are combinations of y' = d e Linear transformations, and 0 0 w 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

c x f y 1 w

Projective Transformations
Projective transformations
Affine transformations, and Projective warps

x' a y ' = d w' g

b e h

c x f y i w

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

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 0 1 w 0 0 0 1 w' 0 0 1


p = T(tx,ty) R() S(sx,sy) p

2D image transformations

These transformations are a nested set of groups Closed under composition and inverse is a member

Image warping

y x f(x,y)

T(x,y) y x g(x,y)

Given a coordinate transform (x,y) = h(x,y) and a source image f(x,y), how do we compute a transformed image g(x,y) = f(T(x,y))?

Forward warping

y x f(x,y)

T(x,y) y x g(x,y)

Send each pixel f(x,y) to its corresponding location (x,y) = T(x,y) in the second image Q: what if pixel lands between two pixels?

Forward warping

y x f(x,y)

T(x,y) y x g(x,y)

Send each pixel f(x,y) to its corresponding location (x,y) = T(x,y) in the second image Q: what if pixel lands between two pixels? A: distribute color among neighboring pixels (x,y)
Known as splatting

Inverse warping

y x f(x,y)

T-1(x,y) y x g(x,y)

Get each pixel g(x,y) from its corresponding location (x,y) = T-1(x,y) in the first image Q: what if pixel comes from between two pixels?

Inverse warping

y x f(x,y)

T-1(x,y) y x g(x,y)

Get each pixel g(x,y) from its corresponding location (x,y) = T-1(x,y) in the first image Q: what if pixel comes from between two pixels? A: Interpolate color value from neighbors
nearest neighbor, bilinear, Gaussian, bicubic

Bilinear interpolation
Sampling at f(x,y):

Forward vs. inverse warping


Q: which is better? A: usually inverseeliminates holes
however, it requires an invertible warp functionnot always possible...

You might also like