Shape and Boundaries
Learn how active contours, or snakes, deform around object boundaries in digital image processing, using energy minimization and dynamic programming for curve matching and segmentation.
Shape and Boundaries
E N D
Presentation Transcript
Shape and Boundaries ECE 847:Digital Image Processing Stan Birchfield Clemson University
Active contours (Snakes) • User (or higher-level process) initializes contour • Snake deforms and shrink-wraps around object boundary (Diagram courtesy “Snakes, shapes, gradient vector flow”, Xu, Prince)
Active contours (Snakes) • Snake is a parameterized curve: • Snake is a type of deformable contour open curve s=0 s=1 s=1 s=0 closed curve
Snakes • Goal: Match curve (boundary) to image data • Approach: minimize energy functional • Like many vision problems, this is underconstrained regularization (impose smoothness prior) image data internal (smoothness) user-supplied Snakes are a top-down approach to segmentation
elasticity 1st-order term membrane a controls tension along spline stretching balloon or elastic band stiffness 2nd-order term thin plate b controls rigidity of spline bending thin plate or bending wire Internal energy a and b may vary along curve but are usually constant
Elasticity draws points together shrinks contour Stiffness minimizes curvature Elasticity (a) and Stiffness (b) Dv v v+Dv
elasticity Ideal curve is point (circle with zero radius) stiffness Ideal curve is circle (no shrinking) Elasticity (a) and Stiffness (b)
Image energy We will use only edges (wline = wterm = 0) Alternatives for edge are Key: function must be monotonic non-increasing
Discrete formulation • Curve represented as n points: • Energy: indices are modulo n for closed curve to handle wraparound Note: We will represent the curve simply as a polygon, with the points being the vertices
How to minimize energy • Two approaches: • Finite element and calculus of variations [Kass, Witkin, and Terzopoulos, IJCV 1988] • Dynamic programming [Amini, Weymouth, and Jain, PAMI 1990] • We will only describe the latter, which is much simpler
Basic framework • Start with initial contour • Allow each point to move to one of 9 positions (3x3 neighborhood) • Algorithm:
Dynamic programming for snakes • Exploit Markov property of internal energy: point is conditionally independent of all other points, given its immediate neighbors • Dynamic programming can exhaustively consider all 9n possibilities with just O(92n) computations
DP Algorithm • Simplifications: • Consider just first-order term (b=0) • Open curve • Construct table (n columns, 9 rows) • Cell (i,j) represents location i for point j • Each cell contains two values: • fij – Cost of best path that ends in point j being in location i • pij – Index of location (0,..,8) for previous point j-1 corresponding to this path • Fill table one column at a time from left to right • Minimum fij in last column indicates best curve
DP (1st order, open curve) • Each cell must consider all 9 possibilities from previous column • First column ignores internal energy: j i
Closed curves • Previous algorithm implements • For closed curves, add term to last column for P(vn-1|v0): • Optimality is lost no matter what m is chosen (could traverse path backwards to find m, but no better than assuming fixed m) • In fact, snake will go haywire near v0 and vn-1 • Solutions: • Run DP 9 times, using different choice of location for v0 each time; select the choice with the minimum cost (optimal, but expensive) • Fold curve back onto itself, so that v1 and vn-1 are both considered in the second column, etc. (optimal, but even more expensive: O(94n) instead of O(92n)) • Keep adding columns to table until path stabilizes (sounds good, but untested) • Recommended solution: Run DP twice (“probably optimal” in practice, but not guaranteed)
Running DP twice • Solution: • Run once • Pick v0, run DP (with an extra term in the last column) • Find min cell of last column, trace p back to find path • Discard everything except the location for the point halfway from endpoints, vn/2 • Run again • Set vn/2 to be the new v0, shifting all other indices down accordingly • Run DP again (with an extra term in the last column) • Find min cell of last column, trace p back to find “probably optimal” path • Now adjust points on snake according to path; this is one iteration • Rationale: The errors due to the open curve assumption should have little effect on points far from the endpoints
Including second-order term • DP will not let us look at future columns: |vi-1-2vi+vi+1|2 • So reformulate: |vi-2vi-1+vi-2|2 • But DP will not let us skip columns, either • So need to increase the state space • Now we have 9x9=81 rows and n columns
Including second-order term • Each cell represents locations for two adjacent points • Each cell has 81 elements in previous column, but only 9 are consistent with the cell | (vi-2,vi-1) | (vi-1,vi) | • Computation is O(93n) must refer to the same location k and j are consistent
DP (second-order) • Simple example: Each point can only move vertically (-1,0,1) only 3 previous cells are consistent j i
Application: Medical imaging Active Contours and their applications – Julien Jomier - Comp 258 Fall 2002
Examples Hands People Active Contours and their applications – Julien Jomier - Comp 258 Fall 2002
More examples Highway Heart Active Contours and their applications – Julien Jomier - Comp 258 Fall 2002
Drawbacks of snakes • Sensitive to initial position • Sensitive to parameters • Small capture range • Fails to detect concavities
Gradient vector flow (GVF) • The GVF field is defined to be a vector field V(x,y) = • Force equation of GVF snake • V(x,y) is defined such that it minimizes the energy functional C. Xu and J. L. Prince , "Snakes, Shape, and Gradient Vector Flow“, IEEE Transactions on Image Processing, 1998. f(x,y) is the edge map of the image. [from Amyn Poonawala]
A look into the vector field components of GVF u(x,y) v(x,y) Note forces also act inside the object boundary!! [from Amyn Poonawala]
GVF Results Traditional snake GVF snake [from Amyn Poonawala]
With GVF, the contour can also be initialized across the boundary of object!! Something not possible with traditional snakes. [from Amyn Poonawala]
Level sets • Embed curve in one higher dimension; curve is given by zero level set of implicit function (i.e., intersection of function with z=0) • Due to J. Sethian and S. Osher 1988www.math.berkeley.edu/~sethian/level_set.html • Fixes several problems of snakes: • Snake intersects itself • Topology changes
Moving contour using level set • Define level set function z = ((x,y,t)=0) • Move the level set function, (x,y,t), so that it rises, falls, expands, etc. • By convention, <0 inside the curve and >0 outside the curve from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Level set evolution As the surfacechanges, sodoes the zero level set from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Curve evolution • 2D: • Curve • Implicit function • Over time: • Curve • Implicit function • Evolution • of curve • of implicit function Simplest implementation:
Advantages Advantages of level sets over snakes: • Curve may change topology and form sharp corners (“weak solutions”) • Discrete grid and finite differences approximate solution • Instrinsic geometric properties are easily determined • normal vector • curvature • Formulation is same for 2D or 3D
Fast Marching Method • J. Sethian, 1996 • Special case that assumes the velocity field, F, never changes sign. That is, contour is either always expanding or always shrinking • Can convert problem to a stationary formulation on a discrete grid where the contour is guaranteed to cross each grid point at most once from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Fast Marching Method • Compute T(x,y) = time at which the contour crosses grid point (x,y) • At any height, T, the surface gives the set of points reached at time T from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Fast Marching Method (i) (ii) (iii) (iv) from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Fast Marching Algorithm • Construct the arrival time surface T(x,y) incrementally: • Build the initial contour • Incrementally add on to the existing surface the part that corresponds to the contour moving with speed F • Builds level set surface by scaffolding the surface patches farther and farther away from the initial contour from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Fast Marching Visualization from http://pages.cs.wisc.edu/~fan/LevelSet/Level_presentation/levelsets.ppt
Mumford-Shah • Mumford-Shah functional captures how well reconstructed function matches original image • Regularization term enforces smoothness, but not at boundaries contour reconstruction imagedomain D. Mumford and J. Shah. Boundary detection by minimizing functionals. CVPR, 1985.
Chan-Vese model • Snakes and level sets have several problems: • Small basin of attraction (edges) • initial contour must surround object (or be completely contained within it • Chan-Vese (2001) propose • segmenting image using model of interior and exterior • level set function is used to represent the curve (or equivalently the binary mask of the interior region) • for simplicity, assume interior and exterior both have approximately constant intensity (but different from each other)
Chan-Vese (cont.) • Goal is to minimize energy functionalwhere • and • m, n, li, and lo are constants • G is contour • w is interior region bounded by G • ci and co are average intensities inside and outside G
Heaviside function: derivative: regularized Heaviside function: derivative: Chan-Vese (cont.) vs. (other functions are possible) Dirac delta function “hard threshold, not differentiable” “soft threshold, differentiable”
Chan-Vese (cont.) • H(f(x,y)) is approximately 1 inside contour, and approximately 0 outside • Therefore,
Chan-Vese (cont.) • Now express the gradient of H(f(x,y)) in terms of the gradient of f(x,y): • Therefore,
Chan-Vese (cont.) • Because we are minimizing an energy functional, you shouldn’t be surprised that we will be using the Euler-Lagrange equation • In preparation, note that • where
Chan-Vese (cont.) • Now let us take some derivatives: • And,