Professional Documents
Culture Documents
Summary
Warping and Interpolation
goal
I understand and compute image transformations such as
Warping and Interpolation
warp function
⇔ a transformation T that alters the geometry of an image
Warping and Interpolation
warp function
⇔ a transformation T that alters the geometry of an image
in other words
I if g(u, v) = g(u) denotes the original image and
h(x, y) = h(x) denotes the warped image and if
x T (u, v)
= x or simply x = T(u)
y Ty (u, v)
then
h(x) = h T(u) = g(u)
Warping and Interpolation
y
v
u x
function g(u) warped function h T(u) = h(x)
Warping and Interpolation
example
I horizontal scaling by a factor of 4
for v in range(rmax): # iterate over rows
for u in range(cmax): # iterate over columns
x = 4.0 * u # compute x = T_x(u,v)
y = v # compute y = T_y(u,v)
if x < cmax:
h[y,x] = g[v,u]
T
Warping and Interpolation
example (cont.)
problem
I method leapfrogs coordinates in the destination image
Warping and Interpolation
problem
I method leapfrogs coordinates in the destination image
h(0, r) → g(0, r)
h(4, r) → g(1, r)
h(8, r) → g(2, r)
..
.
I but then what about h(1, r), h(2, r), h(3, r), . . . ?
Warping and Interpolation
problem
I method leapfrogs coordinates in the destination image
h(0, r) → g(0, r)
h(4, r) → g(1, r)
h(8, r) → g(2, r)
..
.
I but then what about h(1, r), h(2, r), h(3, r), . . . ?
solution . . .
Warping and Interpolation
u = T −1 (x)
u = T −1 (x)
example
I horizontal scaling by a factor of 4
for y in range(rmax): # iterate over rows
for x in range(cmax): # iterate over columns
u = x / 4.0 # compute u = T_xˆ-1(x,y)
v = y # compute v = T_yˆ-1(x,y)
h[y,x] = resample(g, v, u)
−1
T
Warping and Interpolation
example (cont.)
note:
note:
note:
interpolation of 1D functions
I given: a discrete 1D function f that assumes values f [xi ]
at sample points xi
xi 6 x 6 xi+1
Warping and Interpolation
interpolation of 1D functions
I given: a discrete 1D function f that assumes values f [xi ]
at sample points xi
xi 6 x 6 xi+1
note:
example
150 150
f (x)
100 f [xi ] 100
50 50
0 0
0 2 4 6 8 10 0 2 4 6 8 10
-50 -50
-100 -100
nearest-neighbor interpolation
I round x to closest sample point
f [xi ], if | x − xi | 6 | x − xi+1 |
f̂ (x) =
f [xi+1 ], otherwise
0
0 2 4 6 8 10
-50
-100
nn-interpolation
Warping and Interpolation
linear interpolation
f̂ (x) = f [xi ] + δ
xi x xi+1
δ f [xi+1 ] − f [xi ] δ
= x − xi xi+1 − xi
f [xi+1 ] − f [xi ]
⇔ δ = (x − xi ) ·
xi+1 − xi
Warping and Interpolation
linear interpolation
I in python, we may implement this as a function
def linearInterpol1D (a, fa, b, fb, x, eps=0.00001):
if abs(x-a) < eps or abs(a-b) < eps:
return fa
else
return fa + (x-a)*(fb-fa)/(b-a)
150
f (x)
100 fˆ(x)
f [xi ]
50
0
0 2 4 6 8 10
-50
-100
linear interpolation
Warping and Interpolation
problem
I both methods are rather imprecise
Warping and Interpolation
problem
I both methods are rather imprecise
problem
I both methods are rather imprecise
solution
I interpolation using higher order polynomials
I next , we discuss two methods out of a many
possible approaches
Warping and Interpolation
X
n X
n Y x − xk
f̂ (x) = f [xi ] Li (x) = f [xi ]
xi − xk
i=0 i=0 k6=i
Warping and Interpolation
problem
I the function f̂ (x) resulting from L-interpolation of
n + 1 sample points is a polynomial of degree n
-100
L-interpolation
Warping and Interpolation
where
φi (x) = ai (x − xi )3 + bi (x − xi )2 + ci (x − xi ) + di
for i = 1, 2, . . . , n − 1
Warping and Interpolation
φi+1(x)
φi (x)
φi−1 (x)
150
f (x)
100 fˆ(x)
f [xi ]
50
0
0 2 4 6 8 10
-50
-100
Warping and Interpolation
Question:
I how to determine the coefficients in
φi (x) = ai (x − xi )3 + bi (x − xi )2 + ci (x − xi ) + di ?
Answer:
I for the first and second derivative of each φi (x) we have
..
.
Warping and Interpolation
Answer (cont.):
I after some straightforward algebra
6
Mi + 4Mi+1 + Mi+2 = f [xi ] − 2f [xi+1 ] + f [x i+2 ]
h2
for i = 1, 2, . . . , n − 2
note:
note:
note:
Answer (cont.):
I this leads to a solvable system of linear equations that can
be written in form of a matrix equation
Answer (cont.):
I this leads to a solvable system of linear equations that can
be written in form of a matrix equation