Download presentation
Presentation is loading. Please wait.
Published byFelicity Dennis Modified over 9 years ago
1
Warping CSE 590 Computational Photography Tamara Berg
2
Picture Time!
3
Image Warping Slides from: Alexei Efros & Steve Seitz http://www.jeffrey-martin.com
4
D'Arcy Thompson http://www-groups.dcs.st-and.ac.uk/~history/Miscellaneous/darcy.html http://en.wikipedia.org/wiki/D'Arcy_Thompson Importance of shape and structure in evolution Slide by Durand and Freeman Image Warping in Biology
5
Image Transformations image filtering: change range of image g(x) = T(f(x)) f x T f x f x T f x image warping: change domain of image g(x) = f(T(x))
6
Image Transformations TT f f g g image filtering: change range of image g(x) = T(f(x)) image warping: change domain of image g(x) = f(T(x))
7
Parametric (global) warping Examples of parametric warps: translation rotation aspect affine perspective cylindrical
8
Parametric (global) warping 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 T as a matrix: p’ = Mp T p = (x,y)p’ = (x’,y’)
9
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 2
10
Non-uniform scaling: different scalars per component: Scaling X 2, Y 0.5
11
Scaling Scaling operation: Or, in matrix form: scaling matrix S What’s inverse of S?
12
2-D Rotation (x, y) (x’, y’) x’ = x cos( ) - y sin( ) y’ = x sin( ) + y cos( )
13
2-D Rotation (x, y) (x’, y’)
14
2-D Rotation x = r cos ( ) y = r sin ( ) x’ = r cos ( + ) y’ = r sin ( + ) (x, y) (x’, y’)
15
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( ) cos( ) + r cos( ) sin( ) (x, y) (x’, y’)
16
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( ) cos( ) + r cos( ) sin( ) Substitute… x’ = x cos( ) - y sin( ) y’ = x sin( ) + y cos( ) (x, y) (x’, y’)
17
2-D Rotation This is easy to capture in matrix form: What is the inverse transformation? Rotation by – For rotation matrices R (x, y) (x’, y’)
18
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Identity?
19
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Identity?
20
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Identity? 2D Scale?
21
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Identity? 2D Scale?
22
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Rotate around (0,0)? 2D Shear?
23
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Mirror about Y axis?
24
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Mirror about Y axis?
25
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Mirror about Y axis? 2D Mirror over (0,0)?
26
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Mirror about Y axis? 2D Mirror over (0,0)?
27
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Translation?
28
2x2 Matrices What types of transformations can be represented with a 2x2 matrix? 2D Translation? NO!
29
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 Ratios are preserved Closed under composition
30
Homogeneous Coordinates Q: How can we represent translation as a 3x3 matrix?
31
Homogeneous Coordinates Homogeneous coordinates represent coordinates in 2 dimensions with a 3-vector
32
Homogeneous Coordinates 2D Points Homogeneous Coordinates Append 1 to every 2D point: (x y) (x y 1) Homogeneous coordinates 2D Points Divide by third coordinate (x y w) (x/w y/w) Special properties Scale invariant: (x y w) = k * (x y w) (x, y, 0) represents a point at infinity (0, 0, 0) is not allowed 1 2 1 2 (2,1,1) or (4,2,2)or (6,3,3) x y Scale Invariance
33
Homogeneous Coordinates Q: How can we represent translation as a 3x3 matrix?
34
Homogeneous Coordinates Q: How can we represent translation as a 3x3 matrix? A: Using the rightmost column:
35
Translation Example of translation t x = 2 t y = 1 Homogeneous Coordinates
36
Translation Example of translation t x = 2 t y = 1 Homogeneous Coordinates
37
Basic 2D Transformations Basic 2D transformations as 3x3 matrices Translate RotateShear Scale
38
Matrix Composition Transformations can be combined by matrix multiplication p’ = T(t x,t y ) R( ) S(s x,s y ) p
39
Affine Transformations Affine transformations are combinations of … Linear transformations, and 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
40
Projective Transformations Projective transformations … Affine transformations, and Projective warps 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
41
Recovering Transformations What if we know f and g and want to recover the transform T? willing to let user provide correspondences –How many do we need? xx’ T(x,y) yy’ f(x,y)g(x’,y’) ?
42
Translation: # correspondences? How many correspondences needed for translation? xx’ T(x,y) yy’ ?
43
Translation: # correspondences? How many correspondences needed for translation? How many Degrees of Freedom? xx’ T(x,y) yy’ ?
44
Translation: # correspondences? How many correspondences needed for translation? How many Degrees of Freedom? What is the transformation matrix? xx’ T(x,y) yy’ ?
45
Euclidian: # correspondences? How many correspondences needed for translation+rotation? How many DOF? xx’ T(x,y) yy’ ?
46
Affine: # correspondences? How many correspondences needed for affine? How many DOF? xx’ T(x,y) yy’ ?
47
Affine: # correspondences? How many correspondences needed for affine? How many DOF? xx’ T(x,y) yy’ ?
48
Projective: # correspondences? How many correspondences needed for projective? How many DOF? xx’ T(x,y) yy’ ?
49
Example: warping triangles Given two triangles: ABC and A’B’C’ in 2D (12 numbers) Need to find transform T to transfer all pixels from one to the other. How can we compute the transformation matrix: T(x,y) ? A B C A’ C’ B’ SourceDestination
50
Example: warping triangles Given two triangles: ABC and A’B’C’ in 2D (12 numbers) Need to find transform T to transfer all pixels from one to the other. How can we compute the transformation matrix: T(x,y) ? A B C A’ C’ B’ SourceDestination cp2transform in matlab! input – correspondences. output – transformation.
51
Image warping Given a coordinate transform (x’,y’) = T(x,y) and a source image f(x,y), how do we compute a transformed image g(x’,y’) = f(T(x,y))? xx’ T(x,y) f(x,y)g(x’,y’) yy’
52
f(x,y)g(x’,y’) Forward warping Send each pixel f(x,y) to its corresponding location (x’,y’) = T(x,y) in the second image xx’ T(x,y) Q: what if pixel lands “between” two pixels? yy’
53
f(x,y)g(x’,y’) Forward warping Send each pixel f(x,y) to its corresponding location (x’,y’) = T(x,y) in the second image xx’ T(x,y) Q: what if pixel lands “between” two pixels? yy’ A: distribute color among neighboring pixels (x’,y’) –Known as “splatting”
54
Image warping Given a coordinate transform (x’,y’) = T(x,y) and a source image f(x,y), how do we compute a transformed image g(x’,y’) = f(T(x,y))? xx’ T(x,y) f(x,y)g(x’,y’) yy’ imtransform in matlab! input – transform and source image output – transformed image.
55
Warping in action HP commercial
56
Warping in action + TargetSource
57
Warping in action + TargetSource = Result
58
Warping in action + TargetSource User clicks on 4 points in target, 4 points in source.
59
Warping in action + TargetSource User clicks on 4 points in target, 4 points in source. Find best affine transformation between source subimg and target subimg.
60
Warping in action + TargetSource User clicks on 4 points in target, 4 points in source. Find best affine transformation between source subimg and target subimg. Transform the source subimg accordingly.
61
Warping in action + TargetSource User clicks on 4 points in target, 4 points in source. Find best affine transformation between source subimg and target subimg. Transform the source subimg accordingly. Insert the transformed source subimg into the target image.
62
Warping in action + TargetSource User clicks on 4 points in target, 4 points in source. Find best affine transformation between source subimg and target subimg. Transform the source subimg accordingly. Insert the transformed source subimg into the target image.
63
Warping in action + TargetSource = Result
64
Matlab Demo
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.