Raster Analysis in the Browser Brendan Collins, Blue Raster LLC.
Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two...
Transcript of Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two...
![Page 1: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/1.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 1 / 21
Image morphing
© 1998-2015 Josef Pelikán
CGG MFF UK Praha
http://cgg.mff.cuni.cz/~pepca/
![Page 2: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/2.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 2 / 21
Morphing – „image transition”
transition between two raster images– continuous transformation– „in-between” frame generation
geometric deformation (warping)– image space warp (domain transform)
change of attribute (image) function– color/attribute transition (range transform)
![Page 3: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/3.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 3 / 21
Diagram
image coordinates
[x,y] U R2 [u,v] U’ R2
g
f0
attribute space (color)
[R,G,B,..]
f1
time
source target
![Page 4: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/4.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 4 / 21
Interpolation of deform. function
g x y t x y U Rt , , ,0 1 2
Introducing time variable into g function:
g x y x y
g x y g x y u v0
1
, ,
, , ,
Boundary conditions:
g0g0.5
g1
![Page 5: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/5.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 5 / 21
Interpolation of image function
f g x y t f x y t f g x y
t x y U R
t t , , ,
, ,
1
0 1
0 1 1
2
Image function in time t:
can be precomputed
f0 f0.5 f1
![Page 6: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/6.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 6 / 21
defined by [triangle] meshes– individual vertices can move in time (triangle mesh,
spline net, ..)
defined by a set of features– interpolation of arrow endpoints– better: arrow centers, lengths and orientations
deformation of a planar polygon– transition function should minimize deformation
energy
Deformation
![Page 7: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/7.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 7 / 21
shape transition between two planar polygons– need not to have the same number of vertices– continuous transform (for „in-betweening”)
method based on physics– elastic wire model – deformation work minimization– „stretching” and „bending” work
Planar polygon blending
![Page 8: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/8.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 8 / 21
Linear vertex-position interpolation
P P P P P
P P P P PN
N
0 0 0 0 0
1 1 1 1 10 1 0
0 1 0
, ,
, ,
Polygons with equal number of vertices:
P t t P t Pi i i 1 0 1Intermediate position of Pi:
P(0)
P(1)
P(0.5)
![Page 9: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/9.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 9 / 21
Angle interpolation
i 0
Pi(0)
Pi-1(0)
Pi+1(0)Bi(0)Fi(0)
Pi(0.5)
Pi(1)Pi-1(0.5)
Pi-1(1)
Pi+1(0.5)
Pi+1(1)
i 0 5.
i 1
![Page 10: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/10.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 10 / 21
Inner angles
i i i i
i i
t P t P t P t
B t F t
1 1
0
, ,
, ,
tan , ,
A BA BA B
x y x yx x y y
A B B A
A B A B
0
For angle between two adjacent line segments:
tan ii i
i i
tB t F tB t F t
y t y t t y t
x t x t t x t
02
1 22
02
1 22
1 2 1
1 2 1
![Page 11: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/11.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 11 / 21
Inner angles
Q x y F B F B
Q x yF B F B
F B F B
Q x y F B F B
i i i i
i i i i
i i i i
i i i i
0 0 0
1 1 1
12
12
2 2 2
0 0 0 0
1 0 0 1
1 0 0 1
1 1 1 1
, ,
,,
, ,
Q t Q t Q t t Q t 02
1 221 2 1
Quadratic Bézier curve defined by control points Qi:
while this holds: i t Q t 1 0 0 0, , , ,
![Page 12: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/12.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 12 / 21
Evolution of an inner angle
0
90
180
270
monotone Q0
Q1
Q2
Q0
Q1Q2
one turning point
Q0
Q1Q2
zero crossing
![Page 13: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/13.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 13 / 21
„Stretching” work
WA EL
2
02From physics we have:
A cross section
E elastic modulus
L0 original length of the segment
(absolute) stretching
There would be infinite work to shrinking a segmentinto one point!
![Page 14: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/14.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 14 / 21
„Stretching” work
W
k L L
c L L c L LSS
e
S S
S
1 0
0 1 0 11 min , max ,
Modified formula:
k A ES elastic modulus times cross-section
eS elastic „exponent“ (1 .. plastic, 2 .. elastic)
cS degeneration penalty
![Page 15: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/15.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 15 / 21
„Bending” work
W k m p QB B Be
BB
total inner angle change
kB bending elastic modulus
mB penalty for non-monotony
„fold“ of the inner anglepB penalty for zero-crossing („turnover”),
zero if Q(t) does not cross zero
![Page 16: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/16.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 16 / 21
sum of all the „stretching” and „bending” components– „stretching” work for each segment– „bending” work for each vertex
polygon size normalization– „stretching” work is not scale-invariant– uniform scaling to the same size of bounding
rectangle's largest side
Total deformation work
![Page 17: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/17.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 17 / 21
looking for an optimal source-to-target vertex assignment– transition of vertices is given (linear)– to minimize total deformation work– not expecting equal number of vertices edge
degenerations– too large edges could be split in preprocessing
dynamic algorithm .. O(MN)– assignment of short sequences largest sequences
Global optimization
![Page 18: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/18.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 18 / 21
Assignment graph
1:1 assignment
P(0)
P(1)
0 1 M-1 M=0
1
2
N-1
N=0
2
collapse in P(0)
collapse in P(1)
„stretching” work(one edge)
„bending” work(two adjacent edges)
forbidden !
![Page 19: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/19.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 19 / 21
Algorithm
looking for a path from [0,0] to [M,N] with minimal cost– the path cannot return or turn by 90°
each edge has its „stretching“ work
each couple of adjacent edges define „bending” work
dynamic programming – each path prefix has three values in the working matrix– if it went E, SE or S
![Page 20: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/20.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 20 / 21
General algorithm
looking for a path from [i,0] to [i,N] with minimal cost
trying all potential starting points [i,0]
cyclic connection of left/right boundaries (toroidal topology)
one level higher complexity
O(M N M) working matrix
![Page 21: Raster image morphingcgg.mff.cuni.cz/~pepca/lectures/pdf/2d-05-morphing.en.pdftransition between two raster images –continuous transformation –„in-between” frame generation](https://reader036.fdocuments.us/reader036/viewer/2022062604/5fc241dd1b05e3434b5763d5/html5/thumbnails/21.jpg)
Morphing 2015 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 21 / 21
The End
More info:
J. Gomes et al.: Warping and Morphing of Graphical Objects, C.N., SIGGRAPH’95
T. Sederberg, E. Greenwood: A Physically Based Approach to 2D Shape Blending, SIGGRAPH’92