SLIDE 1 IMAGE WARPING
Vuong Le
University of Illinois
ECE 417 – Spring 2013 With some slides from Alexei Efros, Steve Seitz, Jilin Tu, and Hao Tang
SLIDE 2 Content
- Introduction
- Parametric warping
- Barycentric
coordinates
SLIDE 3 Content
- Introduction
- Parametric warping
- Barycentric
coordinates
SLIDE 4 Image Warping
image filtering: change range of image g(x) = T(f(x))
f x
T
g x f x
T
g x
image warping: change domain of image g(x) = f(T(x))
SLIDE 5 Image Warping
image filtering: change range of image g(x) = T(f(x))
T T
f f g g
image warping: change domain of image g(x) = f(T(x))
SLIDE 6 Global parametric image warping
Examples of parametric warps:
translation rotation aspect affine perspective cylindrical
SLIDE 7 Piecewise parametric image warping
- Define a mesh of small shape units: triangles/quadrangles
- Apply different transformations for different units
M1 M2
SLIDE 8 Non-parametric warping
- Move control points of a grid
- Use thin plate splines to produces a smooth vector field
SLIDE 9
Image morphing
SLIDE 10
SLIDE 11
Photoshop examples
SLIDE 12
Photoshop examples
SLIDE 13 Content
- Introduction
- Parametric warping
- Barycentric
coordinates
SLIDE 14 Parametric image warping
Transformation T is a coordinate-changing machine: What does it mean that T is parametric?
° can be described by just a few numbers (parameters)
How to represent global and local transforms?
° Global: T Is the same for any point p in the image ° Local: T can be different at different location
Let’s try to represent T as a matrix: p’ = Mp T p = (x,y) p’ = (x’,y’)
= y x y x M ' '
SLIDE 15
Scaling
Scaling operation: Or, in matrix form:
by y ax x = = ' ' = y x b a y x ' '
scaling matrix S
SLIDE 16
2-D Rotation
θ
(x, y) (x’, y’)
x’ = x cos(θ) - y sin(θ) y’ = x sin(θ) + y cos(θ)
( ) ( ) ( ) ( )
− = y x y x θ θ θ θ cos sin sin cos ' '
R
SLIDE 17 Shearing in x
The y coordinates are unaffected, but the x coordinates are translated linearly with y That is
' * '
y
x x sh y y y = + =
' 1 ' 1
y
x sh x y y =
SLIDE 18 Shearing in y
' ' *
x
x x y sh x y = = +
1 ' 1 '
x
x x sh y y =
SLIDE 19 2x2 Matrices
What types of transformations can be represented with a 2x2 matrix? 2D Shear?
y x sh y y sh x x
y x
+ = + = * ' * '
= y x sh sh y x
y x
1 1 ' '
2D Mirror about Y axis?
y y x x = − = ' '
− = y x y x 1 1 ' '
2D Mirror over (0,0)?
y y x x − = − = ' '
− − = y x y x 1 1 ' '
SLIDE 20 2x2 Matrices
What types of transformations can be represented with a 2x2 matrix? 2D Translation?
y x
t y y t x x + = + = ' '
Only linear 2D transformations can be represented with a 2x2 matrix
NO!
SLIDE 21 All 2D Linear Transformations
Linear transformations are combinations of …
° Scale, ° Rotation, ° Shear, and ° Mirror
Properties of linear transformations:
° Origin maps to origin ° Lines map to lines ° Parallel lines remain parallel ° Distance or length ratios are preserved on parallel lines ° Ratios of areas are preserved
= y x d c b a y x ' '
SLIDE 22 Homogeneous Coordinates
Q: How can we represent translation as a 3x3 matrix?
y x
t y y t x x + = + = ' '
SLIDE 23 Homogeneous Coordinates
Q: How can we represent translation as a 3x3 matrix? A: Using the rightmost column:
= 1 1 1
y x
t t ranslation T
y x
t y y t x x + = + = ' '
' 1 ' 1 * 1 1 1
x y
x t x y t y =
SLIDE 24 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
- Convenient coordinate system to represent many useful
transformations
- (aw, bw, w) represent the same 2D point for any value of w
1 2 1 2
(2,1,1) or (4,2,2) or (6,3,3) x y
SLIDE 25 Basic 2D Transformations
Basic 2D transformations as 3x3 matrices
Θ Θ Θ − Θ = 1 1 cos sin sin cos 1 ' ' y x y x = 1 1 1 1 1 ' ' y x t t y x
y x
= 1 1 1 1 1 ' ' y x sh sh y x
y x
Translate Rotate Shear
= 1 1 1 ' ' y x s s y x
y x
Scale
SLIDE 26 Affine Transformations
Affine transformations are combinations of …
° Linear 2D transformations, and ° Translations
Properties of affine transformations:
° Origin does not necessarily map to origin ° Lines map to lines ° Parallel lines remain parallel ° Length/distance ratios are preserved on parallel lines ° Ratios of areas are preserved
1 2 1 2
1 1 1 x a a a u y b b b v =
SLIDE 27 Solution to Affine Warping
1 2 1 2
1 1 1 x a a a u y b b b v =
SLIDE 28 “Triangle-wise” parametric image warping
- For each transformed image frame
° Define a mesh of triangles ° Find a affine transform from each triangle’s vertices, apply it to other points inside the triangle Have to solve affine transforms at every frame
M1 M2
SLIDE 29 Content
- Introduction
- Parametric warping
- Barycentric coordinates
- Interpolation
- MP6
SLIDE 30
Affine warping for triangles
SLIDE 31
Barycentric Coordinates
SLIDE 32
Barycentric Coordinates
Fact
SLIDE 33 Content
- Introduction
- Parametric warping
- Barycentric
coordinates
SLIDE 34
Image Warping Implementation I
SLIDE 35
Forward Mapping
SLIDE 36
Forward Mapping
SLIDE 37
Forward Mapping
SLIDE 38
Image Warping Implementation II
SLIDE 39
Reverse Mapping
SLIDE 40 Resampling
Evaluate source image at arbitrary (u, v)
° (u, v) does not usually have integer coordinates
Some kinds of resampling
° Nearest neighbor ° Bilinear interpolation ° Gaussian filter
Source Image Destination Image
SLIDE 41
Nearest neighbor
Take value at closest pixel
int iu = trunc(u + 0.5); int iv = trunc(v + 0.5); dst(x, y) = src(iu, iv);
Simple, but causes aliasing
SLIDE 42 Bilinear interpolation
Bilinearly interpolate four surrounding pixels
a = linear interpolation of src(u1, v1) and src(u2, v1) b = linear interpolation of src(u1, v2) and src(u2, v2) dst(x, y) = linear interpolation of ‘a’ and ‘b’ a b
(u1,v1) (u2,v1) (u2,v2) (u1,v2) (x,y)
SLIDE 43
Gaussian Filter
Convolve with Gaussian filter
Width of Gaussian kernel affects bluriness
SLIDE 44
Image Warping Implementation II – with resampling
SLIDE 45
Image Warping Implementation II – with Gaussian resampling
SLIDE 46 Content
- Introduction
- Parametric warping
- Barycentric
coordinates
SLIDE 47 Warping in MP6
° For each triangle find the affine transform ° Apply it to the points inside ° Assign image value to the triangle points
° Barycentric coordinate ° Reverse mapping
SLIDE 48
Preview of MP6