Fitting Deformable contoursweb.cs.ucdavis.edu/~yjlee/teaching/ecs174-spring... · 4/27/2017 1...
Transcript of Fitting Deformable contoursweb.cs.ucdavis.edu/~yjlee/teaching/ecs174-spring... · 4/27/2017 1...
4/27/2017
1
Fitting: Deformable contours
April 27th, 2017
Yong Jae Lee
UC Davis
Recap so far:Grouping and Fitting
Goal: move from array of pixel values (or filter outputs) to a collection of regions, objects, and shapes.
2Slide credit: Kristen Grauman
Grouping: Pixels vs. regions
image clusters on intensity
clusters on colorimage
By grouping pixels based on Gestalt-inspired attributes, we can map the pixels into a set of regions.
Each region is consistent according to the features and similarity metric we used to do the clustering.
Kristen Grauman
3
4/27/2017
2
Fitting: Edges vs. boundaries
Edges useful signal to indicate occluding boundaries, shape.
Here the raw edge output is not so bad…
…but quite often boundaries of interest are fragmented, and we have extra “clutter” edge points.Images from D. Jacobs Kristen Grauman
4
Given a model of interest, we can overcome some of the missing and noisy edges using fittingtechniques.
With voting methods like the Hough transform, detected points vote on possible model parameters.
Fitting: Edges vs. boundaries
Kristen Grauman5
Voting with Hough transform
• Hough transform for fitting lines, circles, arbitrary shapes
x
y
image spacex0
y0 (x0, y0)(x1, y1)
m
b
Hough space
In all cases, we knew the explicit model to fit.
Kristen Grauman6
4/27/2017
3
• Fitting an arbitrary shape with “active” deformable contours
Today
7Slide credit: Kristen Grauman
Deformable contoursa.k.a. active contours, snakes
Given: initial contour (model) near desired object
[Snakes: Active contour models, Kass, Witkin, & Terzopoulos, ICCV1987] Figure credit: Yuri Boykov
8Slide credit: Kristen Grauman
Deformable contours
Given: initial contour (model) near desired object
a.k.a. active contours, snakes
Figure credit: Yuri Boykov
Goal: evolve the contour to fit exact object boundary
[Snakes: Active contour models, Kass, Witkin, & Terzopoulos, ICCV1987]
Main idea: elastic band is iteratively adjusted so as to
• be near image positions with high gradients, and
• satisfy shape “preferences” or contour priors
9Slide credit: Kristen Grauman
4/27/2017
4
Deformable contours: intuition
Image from http://www.healthline.com/blogs/exercise_fitness/uploaded_images/HandBand2-795868.JPG Kristen Grauman
10
Deformable contours vs. Hough
initial intermediate final
Like generalized Hough transform, useful for shape fitting; but
HoughRigid model shape
Single voting pass can detect multiple instances
Deformable contoursPrior on shape types, but shape iteratively adjusted (deforms)
Requires initialization nearby
One optimization “pass” to fit a single contour
Kristen Grauman
11
Why do we want to fit deformable shapes?
• Some objects have similar basic form but some variety in the contour shape.
Kristen Grauman
12
4/27/2017
5
Why do we want to fit deformable shapes?
• Non-rigid, deformable objects can change their shape over time, e.g. lips, hands…
Figure from Kass et al. 1987Kristen Grauman
13
Why do we want to fit deformable shapes?
• Non-rigid, deformable objects can change their shape over time, e.g. lips, hands…
Kristen Grauman
14
Figure credit: Julien Jomier
Why do we want to fit deformable shapes?
• Non-rigid, deformable objects can change their shape over time.
15
4/27/2017
6
Aspects we need to consider
• Representation of the contours
• Defining the energy functions– External
– Internal
• Minimizing the energy function
• Extensions:– Tracking
– Interactive segmentation
Kristen Grauman
16
Representation
• We’ll consider a discrete representation of the contour, consisting of a list of 2d point positions (“vertices”).
),,( iii yx
1,,1,0 ni for
• At each iteration, we’ll have the option to move each vertex to another nearby location (“state”).
),( 00 yx
),( 1919 yx
Kristen Grauman
17
Fitting deformable contours
initial intermediate final
How should we adjust the current contour to form the new contour at each iteration?
• Define a cost function (“energy” function) that says how good a candidate configuration is.
• Seek next configuration that minimizes that cost function.
18
Slide credit: Kristen Grauman
4/27/2017
7
Energy function
The total energy (cost) of the current snake is defined as:
externalinternaltotal EEE
A good fit between the current deformable contour and the target shape in the image will yield a lowenergy.
Internal energy: encourage prior shape preferences: e.g., smoothness, elasticity, particular known shape.
External energy (“image” energy): encourage contour to fit on places where image structures exist, e.g., edges.
19
Slide credit: Kristen Grauman
External energy: intuition
• Measure how well the curve matches the image data
• “Attract” the curve toward different image features
– Edges, lines, texture gradient, etc.
20
Slide credit: Kristen Grauman
External image energy
Magnitude of gradient- (Magnitude of gradient)
22 )()( IGIG yx 22 )()( IGIG yx
How do edges affect “snap” of rubber band?
Think of external energy from image as gravitational pull towards areas of high contrast
21
Slide credit: Kristen Grauman
4/27/2017
8
• Gradient images and
• External energy at a point on the curve is:
• External energy for the whole curve:
),( yxGx ),( yxGy
)|)(||)(|()( 22 yxexternal GGE
External image energy
21
0
2 |),(||),(| iiy
n
iiixexternal yxGyxGE
Kristen Grauman
22
Internal energy: intuition
What are the underlying boundaries in this fragmented edge image?
And in this one?
Kristen Grauman
23
A priori, we want to favor smooth shapes, contours with low curvature, contours similar to a known shape, etc. to balance what is actually observed (i.e., in the gradient image).
Internal energy: intuition
Kristen Grauman
24
4/27/2017
9
Internal energy
For a continuous curve, a common internal energy term is the “bending energy”.
At some point v(s) on the curve, this is:
Tension,Elasticity
Stiffness,Curvature
sd
ddsd
sEinternal 2
2
))((
22
Kristen Grauman
25
• For our discrete representation,
• Internal energy for the whole curve:
10),( niyx iii
i1ivds
d 11112
2
2)()( iiiiiiids
d
1
0
2
11
2
1 2n
iiiiiiinternalE
…
Internal energy
Note these are derivatives relative to position---not spatial image gradients.
Why do these reflect tension and curvature?
Kristen Grauman
26
Example: compare curvature
(1,1) (1,1)
(2,2)
(3,1)(3,1)
(2,5)
2
11 2)( iiiicurvature vE 2
112
11 )2()2( iiiiii yyyxxx
Kristen Grauman
27
4/27/2017
10
Penalizing elasticity
• Current elastic energy definition:
What is the possible problem with this definition?
21
1
0
21 )()( ii
n
iii yyxx
1
0
2
1
n
iiielasticE
Kristen Grauman
28
Penalizing elasticity
• Current elastic energy definition:
1
0
2
1
n
iiielasticE
21
0
21
21 )()(
n
iiiii dyyxx
where d is the average distance between pairs of points – updated at each iteration.
Instead:
Kristen Grauman
29
Dealing with missing data
• The preferences for low-curvature, smoothness help deal with missing data:
[Figure from Kass et al. 1987]
Illusory contours found!
30
Slide credit: Kristen Grauman
4/27/2017
11
Extending the internal energy: capture shape prior
• If object is some smooth variation on a known shape, we can use a term that will penalize deviation from that shape:
where are the points of the known shape.
1
0
2)ˆ(n
iiiinternalE
}ˆ{ i
Fig from Y. Boykov
31
Slide credit: Kristen Grauman
Total energy: function of the weights
externalinternaltotal EEE
1
0
2
11
2
1 2n
iiiiiiinternal dE
21
0
2 |),(||),(| iiy
n
iiixexternal yxGyxGE
32
Slide credit: Kristen Grauman
large small medium
• e.g., weight controls the penalty for internal elasticity
Fig from Y. Boykov
Total energy: function of the weights
33
Slide credit: Kristen Grauman
4/27/2017
12
Recap: deformable contour
• A simple elastic snake is defined by:– A set of n points,
– An internal energy term (tension, bending, plus optional shape prior)
– An external energy term (gradient-based)
• To use to segment an object:– Initialize in the vicinity of the object
– Modify the points to minimize the total energy
Kristen Grauman
34
Energy minimization
• Several algorithms have been proposed to fit deformable contours.
• We’ll look at two:– Greedy search
– Dynamic programming
35
Slide credit: Kristen Grauman
Energy minimization: greedy
• For each point, search window around it and move to where energy function is minimal– Typical window size, e.g., 3 x 3 pixels
• Stop when predefined number of points have not changed in last iteration, or after max number of iterations
• Note:
– Convergence not guaranteed
– Need decent initialization
Kristen Grauman
36
4/27/2017
13
Energy minimization
• Several algorithms have been proposed to fit deformable contours.
• We’ll look at two:– Greedy search
– Dynamic programming
37
Slide credit: Kristen Grauman
1v2v
3v
4v6v
5v
With this form of the energy function, we can minimize using dynamic programming, with the Viterbi algorithm.
Iterate until optimal position for each point is the center of the box, i.e., the snake is optimal in the local search space constrained by boxes.
[Amini, Weymouth, Jain, 1990]Fig from Y. Boykov
Energy minimization: dynamic programming
38
Slide credit: Kristen Grauman
Energy minimization: dynamic programming
1
111 ),(),,(
n
iiiintotal EE
• Possible because snake energy can be rewritten as a sum of pair-wise interaction potentials:
• Or sum of triple-interaction potentials.
1
1111 ),,(),,(
n
iiiiintotal EE
39
Slide credit: Kristen Grauman
4/27/2017
14
Snake energy: pair-wise interactions 2
1
1
211 |),(||),(|),,,,,( iiy
n
iiixnntotal yxGyxGyyxxE
21
1
1
21 )()( ii
n
iii yyxx
1
1
21 ||)(||),,(
n
iintotal GE
1
1
21 ||||
n
iii
),(...),(),(),,( 113222111 nnnntotal vvEvvEvvEE
21
21 ||||||)(||),( iiiiii GE where
Re-writing the above with : iii yxv ,
Kristen Grauman
40
),( 44 nvvE),( 433 vvE
)3(3E
)(3 mE )(4 mE
)3(4E
)2(4E
)1(4E
)(mEn
)3(nE
)2(nE
)1(nE
)2(3E
)1(3E
)(2 mE
)3(2E
),(...),(),( 11322211 nnntotal vvEvvEvvEE
),( 322 vvE
)1(2E
)2(2E
),( 211 vvE
0)1(1 E
0)2(1 E
0)3(1 E
0)(1 mE
(1) for each possible position (state) of vertex, find cost of optimal path arriving there, and optimal position of predecessor.
(2) backtrack from best state for last vertex.
states
1
2
…
m
vert
ices
1v 2v 3v 4v nv
)( 2nmOComplexity: vs. brute force search ____?
Viterbi algorithm
Example adapted from Y. Boykov
41
1v2v
3v
4v6v
5v
With this form of the energy function, we can minimize using dynamic programming, with the Viterbi algorithm.
Iterate until optimal position for each point is the center of the box, i.e., the snake is optimal in the local search space constrained by boxes.
[Amini, Weymouth, Jain, 1990]Fig from Y. Boykov
Energy minimization: dynamic programming
42
Slide credit: Kristen Grauman
4/27/2017
15
),(...),(),( 11322211 nnn vvEvvEvvE DP can be applied to optimize an open ended snake
For a closed snake, a “loop” is introduced into the total energy.
1n
),(),(...),(),( 111322211 vvEvvEvvEvvE nnnnn
1n
2
1n
3 4
Work around:
1) Fix v1 and solve for rest.
2) Fix an intermediate node at its position found in (1), solve for rest.
Energy minimization: dynamic programming
43Slide credit: Kristen Grauman
Aspects we need to consider
• Representation of the contours
• Defining the energy functions– External
– Internal
• Minimizing the energy function
• Extensions:– Tracking
– Interactive segmentation
44
Slide credit: Kristen Grauman
Tracking via deformable contours
1. Use final contour/model extracted at frame t as an initial solution for frame t+1
2. Evolve initial contour to fit exact object boundary at frame t+1
3. Repeat, initializing with most recent frame.
Tracking Heart Ventricles (multiple frames)
Kristen Grauman
45
4/27/2017
16
Visual Dynamics Group, Dept. Engineering Science, University of Oxford.
Traffic monitoringHuman-computer interactionAnimationSurveillanceComputer assisted diagnosis in medical imaging
Applications:
Tracking via deformable contours
Kristen Grauman
46
• May over-smooth the boundary
• Cannot follow topological changes of objects
Limitations
47
Slide credit: Kristen Grauman
Limitations• External energy: snake does not really “see” object
boundaries in the image unless it gets very close to it.
image gradientsare large only directly on the boundary
I
48
4/27/2017
17
Distance transform
• External image can instead be taken from the distance transform of the edge image.
original -gradient distance transform
edges
Value at (x,y) tells how far that position is from the nearest edge point (or other binary mage structure)
Kristen Grauman
49
Deformable contours: pros and cons
Pros:• Useful to track and fit non-rigid shapes
• Contour remains connected
• Possible to fill in “subjective” contours
• Flexibility in how energy function is defined, weighted.
Cons:• Must have decent initialization near true boundary, may
get stuck in local minimum
• Parameters of energy function must be set well based on prior information
Kristen Grauman
50
Summary
• Deformable shapes and active contours are useful for
– Segmentation: fit or “snap” to boundary in image
– Tracking: previous frame’s estimate serves to initialize the next
• Fitting active contours:
– Define terms to encourage certain shapes, smoothness, low curvature, push/pulls, …
– Use weights to control relative influence of each component cost
– Can optimize snakes with Viterbi algorithm.
Kristen Grauman
51
4/27/2017
18
Questions?
See you Tuesday!
52