Lecture 20
Lecture 20
Recap
Summary
Recap
warp function
I a warp function is a transformation T that alters the geometry of
an image, i.e.
g̃(x) = g̃ T(u) = g(u)
example
y
v
u x
T
Warping and Interpolation
problem
I this method leapfrogs coordinates in the destination image
Warping and Interpolation
example
Warping and Interpolation
u = T −1 (x)
−1
T
Warping and Interpolation
example
Warping and Interpolation
xi 6 x 6 xi+1
150 150
f (x)
100 100 f [xi ]
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 the closest sample point
f̂ (x) = f [xk ], where xk = argmin | x − xj |
xj ∈{xi ,xi+1 }
150
f (x)
100 fˆ(x)
f [xi ]
50
0
0 2 4 6 8 10
-50
-100
nn-interpolation
Warping and Interpolation
linear interpolation
I assume f̂ to be piecewise linear
f [xi+1 ] − f [xi ]
f̂ (x) = f [xi ] + (x − xi ) ·
xi+1 − xi
150
f (x)
100 fˆ(x)
f [xi ]
50
0
0 2 4 6 8 10
-50
-100
linear interpolation
Warping and Interpolation
150
f (x)
100 fˆ(x)
f [xi ]
50
0
0 2 4 6 8 10
-50
-100
Lagrange 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
150
f (x)
100 fˆ(x)
f [xi ]
50
0
0 2 4 6 8 10
-50
-100
Warping and Interpolation
φi+1(x)
φi (x)
φi−1 (x)
φi (x) = ai (x − xi )3 + bi (x − xi )2 + ci (x − xi ) + di
φi0 (x) = 3ai (x − xi )2 + 2bi (x − xi ) + ci
φi00 (x) = 6ai (x − xi ) + 2bi
xi+1 − xi = h ∀i (5)
f [xi ] = f̂ (xi ) = φi (xi ) = ai (xi −xi )3 +bi (xi −xi )2 +ci (xi −xi )+di = di (6)
I using
di+1 = ai h3 + bi h2 + ci h + di (7)
Warping and Interpolation
Mi
Mi = 2bi ⇔ bi = (10)
2
I then, becomes
Mi+1 − Mi
ai =
6h
Mi
bi =
2
f [xi+1] − f [xi ] Mi+1 + 2Mi
ci = − h
h 6
di = f [xi ]
Warping and Interpolation
6
Mi + 4Mi+1 + Mi+2 = f [x i ] − 2f [xi+1 ] + f [x i+2 ]
h2
for i = 1, 2, . . . , n − 2
I in matrix form (assuming M1 = Mn = 0)
4 1 0 ··· 0 0 0 f [x1 ] − 2f [x2 ] + f [x3 ]
M2
1 4 1 ··· 0 0 0 M3 f [x2 ] − 2f [x3 ] + f [x4 ]
···
0 1 4 0 0 0 M4 f [x3 ] − 2f [x4 ] + f [x5 ]
.
.. .. .. .. .. .. .. =
6
..
..
. . . . . . . h2
.
0
0 0 ··· 4 1 0 Mn−3
f [xn−4 ] − 2f [xn−3 ] + f [xn−2 ]
0 0 0 ··· 1 4 1 Mn−2 f [x ] − 2f [x ] + f [x ]
n−3 n−2 n−1
0 0 0 ··· 0 1 4 Mn−1 f [xn−2 ] − 2f [xn−1 ] + f [xn ]
Warping and Interpolation
Question:
I why do we consider cubic interpolation polynomials?
Warping and Interpolation
Question:
I why do we consider cubic interpolation polynomials?
Answer:
I consider, for example, the continuous quadratic function
−x2 , if x < 0
f (x) =
x2 , if x > 0
Answer (cont.):
4
0 −2x, if x < 0
f (x) =
2x, if x > 0 0
-8 -4 0 4 8
is continuous, too, . . . -4
f (x)
f ′ (x)
f ′′ (x)
-8
Warping and Interpolation
Answer (cont.):
4
0 −2x, if x < 0
f (x) =
2x, if x > 0 0
-8 -4 0 4 8
is continuous, too, . . . -4
f (x)
f ′ (x)
I . . . the second derivative -8
f ′′ (x)
−2, if x < 0
f 00 (x) =
2, if x > 0
Answer (cont.):
⇒ for functions composed of quadratic polynomials, we
cannot guarantee that they are twice continuously
differentiable
interpolation of 2D Functions
I given: a discrete, 2D function g that assigns values
g[ui , vi ] to coordinates (ui , vi )
Warping and Interpolation
interpolation of 2D Functions
I given: a discrete, 2D function g that assigns values
g[ui , vi ] to coordinates (ui , vi )
ui 6 u 6 ui+1
∧ vi 6 v 6 vi+1
Warping and Interpolation
nearest-neighbor interpolation
I extension of the known approach to the case of 2D data
ĝ(u, v) = g[uk , vl ]
where
(uk , vl ) = argmin
(u, v) − (ui , vj )
i, j
Warping and Interpolation
bilinear interpolation
I extension of the simple 1D approach to 2D data
I can be broken down into three steps . . .
Warping and Interpolation
bilinear interpolation
I extension of the simple 1D approach to 2D data
I can be broken down into three steps . . .
I first:
Warping and Interpolation
bilinear interpolation
I extension of the simple 1D approach to 2D data
I can be broken down into three steps . . .
I second:
Warping and Interpolation
bilinear interpolation
I extension of the simple 1D approach to 2D data
I can be broken down into three steps . . .
I third:
Warping and Interpolation
u = T −1 (x)
u = T −1 (x)
ui+1 − ui → i + 1 − i = 1
and
vj+1 − vj → j + 1 − j = 1
respectively
Warping and Interpolation
i = buc, i + 1 = due
as well as
j = bvc, j + 1 = dve
example
Artistic Image Effects
approach (1D)
g(u)
g̃(x)
Artistic Image Effects
approach (1D)
g(u)
g̃(x)
Artistic Image Effects
approach (1D)
I we consider a warp functionT to the effect
g̃(x̃) = g T(x)
Artistic Image Effects
approach (1D)
I we consider a warp functionT to the effect
g̃(x̃) = g T(x)
and
example
20
1
15 0.8
0.6
10
0.4
5 id(x) 2 /32
T (x) 0.2 1 − e−x
0 0
0 5 10 15 20 0 5 10 15 20
Artistic Image Effects
approach (1D)
I that is
Artistic Image Effects
approach (1D)
I that is
approach (1D)
I that is
approach (1D)
I that is
T(x) = x + δ+ (x)
or
T(x) = x · δ· (x)
Artistic Image Effects
approach (1D)
I for instance, we may choose
x2
δ· (x) = 1 − e− 2σ2
Artistic Image Effects
approach (1D)
I for instance, we may choose
x2
δ· (x) = 1 − e− 2σ2
I interestingly
x2 x2
x · δ· (x) = x · (1 − e− σ2 ) = x − x · e− 2σ2 = x + δ+ (x)
Artistic Image Effects
approach (1D)
I it is also common to define δ+ (x) in a case-based manner
I for instance
+ −x · (1 − σx ) if x 6 σ
δ (x) =
0 otherwise
Artistic Image Effects
approach (2D)
I chose the center µ of the virtual lens
Artistic Image Effects
approach (2D)
I chose the center µ of the virtual lens
I iterate over all pixels in the destination image
Artistic Image Effects
approach (2D)
I chose the center µ of the virtual lens
I iterate over all pixels in the destination image
I compute the polar coordinates of the current pixel
(x, y) → r(µ), ϕ
Artistic Image Effects
approach (2D)
I chose the center µ of the virtual lens
I iterate over all pixels in the destination image
I compute the polar coordinates of the current pixel
(x, y) → r(µ), ϕ
T(r) = r + δ+ (r)
Artistic Image Effects
approach (2D)
I chose the center µ of the virtual lens
I iterate over all pixels in the destination image
I compute the polar coordinates of the current pixel
(x, y) → r(µ), ϕ
T(r) = r + δ+ (r)
on choosing δ+ or δ·
I choice are arbitrary and there are infinitely many ways . . .
Artistic Image Effects
r r2
original δ+ = −r · 1 − rmax δ+ = −r · 1 − 2
rmax
Artistic Image Effects
√2 −r2
rmax r2
δ+ = −r · rmax δ+ = −r · tanh r
rmax δ+ = −r · exp − 21 2
rmax
Artistic Image Effects
I i.e. consider
T = T(r, x)
T(r, x) = x + δ+ (µ − x)
Artistic Image Effects
example
I here, we applied
(µ−x)2
g̃(x) = g(x + e− 2σ2 · (µ − x))
waves effect
I transform the image such that it appears as if on the
bottom of a swimming pool whose water is in motion
example
Artistic Image Effects
approach (1D)
I as usual, we are interested in g̃(x̃) = g T(x)
I we choose
T(x) = x + α sin(νx − φ)
example
I effects of the parameters in T(x) = x + α sin(νx − φ)
id(x) id(x)
10 10
T (x) T1 (x)
T2 (x)
5 5
0 0
0 5 10 0 5 10
example
I effects of the parameters in T(x) = x + α sin(νx − φ)
id(x) id(x)
10 10
T1 (x) T1 (x)
T2 (x) T2 (x)
5 5
0 0
0 5 10 0 5 10
approach (2D)
I again, we follow the idea of a central force
I we choose
r
T(r, x) = x + α sin νkrk − φ ·
krk
= x + ∆(r, α, ν, φ)
Artistic Image Effects
swirl effect
I twist an image about a point µ just as if you would put an
immersion blender into it
example
Artistic Image Effects
swirl effect
I each pixel x of the images is being displaced by a vector ∆
where, for instance
∆⊥r=µ−x
Artistic Image Effects
approach (2D)
I chose the point µ where to insert the virtual blender
Artistic Image Effects
approach (2D)
I chose the point µ where to insert the virtual blender
approach (2D)
I chose the point µ where to insert the virtual blender
r = kµ − xk
µy − y
ϕ = arctan
µx − x
Artistic Image Effects
approach (2D)
I chose the point µ where to insert the virtual blender
r = kµ − xk
µy − y
ϕ = arctan
µx − x
T(ϕ, r) = ϕ + δ+ (ϕ, r)
Artistic Image Effects
approach (2D)
I that is compute an angular displacement depending on the
distance r between the current point x and the center µ of
the rotation
Artistic Image Effects
approach (2D)
I that is compute an angular displacement depending on the
distance r between the current point x and the center µ of
the rotation
approach (2D)
I that is compute an angular displacement depending on the
distance r between the current point x and the center µ of
the rotation
explanation
u
∆
r
x x
r ϕ′ r
ϕ
µ µ
Artistic Image Effects
explanation
I according to figure, we have
u=x+∆ ⇔ ∆=u−x
I on the other hand, we have (using ϕ 0 = T(ϕ, r))
u = µx + r · cos ϕ 0
v = µy + r · sin ϕ 0
x = µx + r · cos ϕ
y = µy + r · sin ϕ
I therefore, it follows that
∆x = u − x = r · (cos ϕ 0 − cos ϕ)
∆y = v − y = r · (sin ϕ 0 − sin ϕ)
which immediately leads to the above equations
Artistic Image Effects
explanation
I this, however, means that we may again understand the
effect to be caused by a central force
T(r, x) = x + ∆(r)
where
cos ϕ(r) + δ+ krk − cos ϕ(r)
∆(r) = krk ·
+
sin ϕ(r) + δ krk − sin ϕ(r)
Summary