Image Warping: 15-463: Computational Photography Alexei Efros, CMU, Fall 2005
Image Warping: 15-463: Computational Photography Alexei Efros, CMU, Fall 2005
http://www.jeffrey-martin.com
Image Warping
image filtering: change range of image g(x) = T(f(x))
f f
T
x x
T
x x
Image Warping
image filtering: change range of image g(x) = h(T(x))
f g
translation
rotation
aspect
affine
perspective
cylindrical
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
x ' a 0 x y ' = 0 b y
scaling matrix S Whats inverse of S?
2-D Rotation
(x, y) (x, y)
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:
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
x' = s x * x y' = s y * y
2x2 Matrices
What types of transformations can be represented with a 2x2 matrix?
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?
x ' = 1 0 x y ' 0 1 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!
x' a b x y ' = c d y
x' = a b e y ' c d g
f i h k
j x l y
ux p' = u y
v x 4 u x = v y 3 u y
vx 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 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
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
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
b e h
c x f y i w
Matrix Composition
Transformations can be combined by matrix multiplication
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):