Presentation is loading. Please wait.

Presentation is loading. Please wait.

Image Warping 2D Geometric Transformations

Similar presentations


Presentation on theme: "Image Warping 2D Geometric Transformations"— Presentation transcript:

1 Image Warping 2D Geometric Transformations
Targil 7 : Image Warping 2D Geometric Transformations

2 Image Warping http://www.jeffrey-martin.com
Many slides from Steve Seitz and Alexei Efros

3 Image Warping image filtering: change range of image
g(x,y) = T( f(x,y) ) f g T image warping: change domain of image g(x) = f( T(x,y) ) f g T

4 Parametric (global) warping
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) Let’s represent T as a matrix: p’ = Mp

5 Parametric (global) warping
Examples of parametric warps: translation scaling rotation mirror affine projective

6 Translation X – 2, Y + 3 Q: How to represent in matrix form?
Translation of a coordinate means adding a scalar to each of its components: X – 2, Y + 3 Q: How to represent in matrix form?

7 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

8 Scaling Non-uniform scaling: different scalars per component: X  2, Y  0.5

9 Scaling Scaling operation: Or, in matrix form: scaling matrix S
What’s inverse of S?

10  (x’, y’) (x, y) x’ = x cos() - y sin() y’ = x sin() + y cos()
2-D Rotation (x, y) (x’, y’) x’ = x cos() - y sin() y’ = x sin() + y cos()

11  (x’, y’) (x, y) f 2-D Rotation x = r cos (f) y = r sin (f)
Trig Identity… x’ = r cos(f) cos() – r sin(f) sin() y’ = r sin(f) cos() + r cos(f) sin() Substitute… x’ = x cos() - y sin() y’ = x sin() + y cos() (x, y) (x’, y’) f

12 2-D Rotation R This is easy to capture in matrix form:
Even though sin(q) and cos(q) are nonlinear functions of q, 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 –q For rotation matrices, det(R) = 1 so R

13 2x2 Matrices 2D Identity? 2D Scale around (0,0)?
What types of transformations can be represented with a 2x2 matrix? 2D Identity? 2D Scale around (0,0)? y y syy y x x x sxx

14 2x2 Matrices 2D Rotate around (0,0)? 2D Shear?
What types of transformations can be represented with a 2x2 matrix? 2D Rotate around (0,0)? 2D Shear? x y Shear along x axis

15 2x2 Matrices 2D Mirror about Y axis? 2D Mirror over (0,0)?
What types of transformations can be represented with a 2x2 matrix? 2D Mirror about Y axis? 2D Mirror over (0,0)?

16 2x2 Matrices 2D Translation? Only linear 2D transformations
What types of transformations can be represented with a 2x2 matrix? 2D Translation? NO! Only linear 2D transformations can be represented with a 2x2 matrix

17 All 2D Linear Transformations
Linear transformations are combinations of scale, rotation and shear. Properties of linear transformations: Origin maps to origin Lines map to lines Parallel lines remain parallel Ratios are preserved (along lines which cross the origin) Closed under composition * What is the inverse transformation?

18 Homogeneous Coordinates
Q: How can we represent translation as a 3x3 matrix?

19 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 1 2 (2,1,1) or (4,2,2) or (6,3,3) x y Convenient coordinate system to represent many useful transformations

20 Homogeneous Coordinates
represent coordinates in 2 dimensions with a 3-vector Multiplying by a scalar does not change our point ! are all equivalent to:

21 Homogeneous Coordinates
Q: How can we represent translation as a 3x3 matrix? A: Using the rightmost column:

22 Translation Homogeneous Coordinates tx = -2 ty = 3
Example of translation Homogeneous Coordinates tx = -2 ty = 3

23 Basic 2D Transformations
Basic 2D transformations as 3x3 matrices Translate Scale Rotate Shear

24 Matrix Composition p’ = T R S p
Transformations can be combined by matrix multiplication Advantages: General purpose representation Hardware matrix multiply Be aware: order of transformations matter! Matrix multiplication is not commutative p’ = T(tx,ty) R(Q) S(sx,sy) p p’ = T R S p

25 Rigid Transformations
Combination of translation and rotation # Parameters: 3 (tx, ty, θ) Preserves all information except of orientation (lengths, angles etc.)

26 Similarity Transformations
Combination of translation, rotation and uniform scaling # Parameters: 4 (s, tx, ty, θ) Preserves proportions and angles, but not length and orientation

27 Affine Transformations
Combination of translation with all 2D linear transformations (rotation, scaling and shear) # Parameters: 6 Preserves parallelism

28 Affine Transformations
When do we meet them ? When the camera is scanning a plane in parallel Camera moving plane

29 Projective Transformations
Affine transformations + projective warps Maps points from a 2D plane to each other 2D plane # Parameters: 8 (the 9th is redundant, since we use homogenous coordinates) Preserves only straight lines (not parallelism, angles etc.)

30 Projective Transformations
Examples of projective Transformations : Camera rotation (same center of projection) / camera varying the focal length Transformation between 2 images induced by a world plane Image of a plane and its shadow on another plane

31 Projective Transformations
Perspective projection (or central projection) is a special case in which the origin (image center) is preserved

32 Distortions under central projection
The origin (image center) is mapped to the origin

33 Removing perspective distortion
Original image Warped image

34 2D image transformations

35 2D image transformations
These transformations are a nested set of groups Closed under composition and inverse is a member

36 Computing transformation
Corresponding sets of points enable computing the transformation matrix each corresponding pair can contribute 2 equations How many points are required for the different transformations (translation, rigid, similarity, affine, projective)?

37 Image warping T(x,y) y y’ x x’ f(x,y) 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))?

38 Forward warping T(x,y) y y’ x x’ f(x,y) 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?

39 Forward warping T(x,y) y y’ x x’ f(x,y) 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”

40 Inverse (backward) warping
T-1(x,y) y y’ x x x’ f(x,y) 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?

41 Inverse warping T(x,y) y’ x x’ f(x,y) 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

42 Bilinear interpolation
Sampling at f(x,y):

43 Forward vs. inverse warping
Q: which is better? A: usually inverse—eliminates holes however, it requires an invertible warp function—not always possible...

44 Warping in Matlab How do we avoid loops ?
Use meshgrid to represent image indexes Use matlab interp2 to perform the interpolation Find holes (NaN) and out of range interpolation values


Download ppt "Image Warping 2D Geometric Transformations"

Similar presentations


Ads by Google