1516 contouring

50
1 CONTOURING By Ashish V. Deshpande Electrical Engineering Department The University of Texas at Arlington June 21 st 2004

Upload: dr-fereidoun-dejahang

Post on 13-Apr-2017

39 views

Category:

Education


0 download

TRANSCRIPT

Page 1: 1516 contouring

1

CONTOURING

By Ashish V. Deshpande

Electrical Engineering DepartmentThe University of Texas at Arlington

June 21st 2004

Page 2: 1516 contouring

2

OVERVIEW

• Geometry of Curves• Contour Properties• Curve Fitting

Page 3: 1516 contouring

3

CONTOUR

• Edges are linked into a representation for a region boundary called contour

• Closed Contour• correspond to region boundaries

• Open Contour• part of a region boundary• gap in boundary : Edge detection

threshold too high , weak contrast

Page 4: 1516 contouring

4

Representing a Contour• Criteria for good representation

• Efficiency: Simple, compact representation.• Accuracy: Fit image features accurately.• Effectiveness: Suitable for the operations

performed in the later stages of the application• Two ways

• Ordered list of edges • Curve (mathematical model of contour eg.Line segments , Cubic

splines etc.)

Page 5: 1516 contouring

5

Representing a Contour• Ordered List

• Efficiency : least compact & simplest• Accuracy : as accurate as estimate of edge

locations• Effectiveness : not good

• Curves• Efficiency : increases• Accuracy : as errors in edge detection are averaged• Effectiveness : increases

Page 6: 1516 contouring

6

Some Definitions• A curve interpolates a set of points if it

passes through the points• Approximation is fitting a curve passing

close to the points but not necessarily through the points

• An edge list is an ordered set of edge points.• A contour is an edge list or the curve that

has been used to represent the edge list.• A boundary is the closed contour that

surrounds a region.

Page 7: 1516 contouring

7

Geometry of Curves

• Representing a point• Explicit form y = f(x)• Implicit form f(x,y)=0• Parametric form (x(u), y(u))

u is the parameter• Length of an arc

2

1

22u

u

dududy

dudx

Page 8: 1516 contouring

8

Contour Properties• Let pi = (xi , yi) be the coordinates of edge i in the edge list

• Estimate the slope using edge points that are not adjacent :• Left k-slope: direction from pi-k to pi• Right k-slope: direction from pi to pi+k • K-curvature: diff. between the left and right k-slopes.

• Length of digital curve

• Distance between end points

• S/D ratio (covered in curve fitting)

n

iiiii yyxxS

2

21

21 )()(

21

21 )()( xxyyD nn

Page 9: 1516 contouring

9

Representation using lists

• Chain Codes : specifies direction of contour at each edge along the edge list • Directions are quantized• Starting at first edge and going clockwise

around the contour the direction is specified using one of the directions

Page 10: 1516 contouring

10

Chain Codes

• Example

• Limitations• Limited set of directions • Sensitive to noise

Page 11: 1516 contouring

11

Slope Representation• Continuous version of Chain code , also called

y-s plot• Algorithm:

1.Start at the first edge and go clockwise 2.Estimate slope (y) and arc length (s)3.Plot the slope Versus the arc length

• Horizontal line segments in y-s space correspond to segments in the contour

• Line segments at other orientations correspond to circular arcs

• Portions of the plot that are not straight line segments correspond to other curve primitives

Page 12: 1516 contouring

12

An Example

Page 13: 1516 contouring

13

Centroidal Profile Representation

• Plot the distance from the centroid to the boundary as a function of angle

Page 14: 1516 contouring

14

Curve Fitting• Four Models

• Line Segments • Circular arcs• Conic sections• Cubic splines

• Note: We proceed with the basic assumption that the edge locations are sufficiently accurate that selected edge points can be used to determine the fit. We will later consider methods based on approximation that can handle such errors.

Page 15: 1516 contouring

15

Goodness of a fit• Let di be the distance of edge point i from line.• Maximum absolute error : measures how much

the points deviate from the curve in the worst case.

• Mean squared error : gives an overall measure of the deviation of the curve from the edge points.

Page 16: 1516 contouring

16

Goodness of a fit contd…• Normalized maximum absolute error: the ratio of the

maximum absolute error to the length of the curve (error becomes independent of the length of the curve ,i.e unitless ).

• Ratio of curve length to the end point distance: a good measure of the complexity of the curve.

• Number of Sign Changes: in the error is a good indicator of the appropriateness of the curve as a model for the edges in the contour.

Page 17: 1516 contouring

17

Curve fitting methods• The use of straight line segments (polylines) is

appropriate if the image consists of straight lines. It is the starting point for fitting other models.

• Circular arcs are a useful representation for estimating curvature

• Conic sections provide a convenient way to represent sequences of line segments and circular as well as elliptic and hyperbolic arcs .

• Cubic splines are good to model smooth curves

Page 18: 1516 contouring

18

Polyline Representation• A polyline is a sequence of line segments joined end to

end. The ends of each line are edge points in the original edge list. The points where line segments are joined are called vertices.

• A quick revision• Equation of line passing from two points (x1, y1), (x2, y2):

• Distance d of edge point (u, v) from the line:

• D is the distance between (x1, y1) and (x2, y2).

Page 19: 1516 contouring

19

Polyline Representation types

• Splitting• Merging• Split and Merge Algorithm• Hop-Along Algorithm

Page 20: 1516 contouring

20

Splitting (Top Down)• Algorithm :

(1) Take the line segment connecting the end points of the contour (if the contour is closed, consider the line segment connecting the two farthest points)

(2) Find the farthest edge point from the line segment(3) If the normalized maximum error of that point from

the line segment is above a threshold, split the segment into two segments at that point (i.e., new vertex)

(4)Repeat the same procedure for each of the two subsegments until the error is very small.

Page 21: 1516 contouring

21

Example (Open Contour)

Page 22: 1516 contouring

22

Example (Closed Contour)

Page 23: 1516 contouring

23

Merging (Bottom Up)• Algorithm :

(1) Use the first two edge points to define a line segment.

(2) Add a new edge point if it does not deviate too far from the current line segment.

(3) Update the parameters of the line segment using least- squares.

(4) Start a new line segment when edge points deviate too far from the line segment.

Page 24: 1516 contouring

24

Tolerance Band• Algorithm:

(1) Two line segments that are parallel to the line segment approximating the edge at a distance from the center are computed.(2) Edges are added to the current line segment as long as the new edges are inside the tolerance band.(3) The parameters of the line segment are recomputed as the edges are added to the segment.(4) The vertex at the end of the segment is the starting point for the next segment

Page 25: 1516 contouring

25

Example

Page 26: 1516 contouring

26

Split and Merge• The accuracy of line segment

approximations can be improved by interleaving merge and split operations.

• Algorithm:(1) After recursive subdivision (split), allow adjacent segments to be replaced by a single segment (merge).(2) Alternate applications of split and merge until no segments are merged or split.

Page 27: 1516 contouring

27

Example

Page 28: 1516 contouring

28

Hop Along Algorithm

1. Start with the first k edges from the list.2. Fit a line segment between the first and the last edges

in the sub list.3. If the normalized maximum error is too large, shorten

the sub list to the point of maximum error. Return to step 2.

4. If the line fit succeeds, compare the orientation of the current line segment with that of the previous line segment. If the lines have similar orientations, replace the two line segments with a single line segment.

5. Make the current line segment the previous line segment and advance the window of edges so that there are k edges in the sublist. Return to step 2.

Page 29: 1516 contouring

29

Circular arcs• Subsequences of the line segments can

be replaced by circular arcs if desired. Replacing by arcs involves fitting circular arcs through the end points of two or more line segments, i.e. fitting is done on vertices in the polyline

• The circular arc is a fit between the first and last end points and one other point. There can be several methods depending on how the middle point is chosen .

Page 30: 1516 contouring

30

Replacing line segments with arcs• Algorithm:

1.Initialize the window of vertices to the 3 end points of the first 2 line segments in the polyline.

2.Compute the ratio of the length of the part of the contour corresponding to the 2 line segments to the distance between the end points. If the ratio is large then leave the first line segment unchanged, advance the window of vertices by one vertex, and repeat this step.

3.Fit a circle through the 3 vertices.4.Calculate the normalized error and number of sign

changes.

Page 31: 1516 contouring

31

Contd…

5. If the normalized maximum error is too large or the number of sign changes is too small then leave the first line segment unchanged, advance the window of vertices and return to step 2.

6.If the circle fit succeeds, then try to include the next line segment in the circular arc. Repeat this step until no more line segments can be sub-summed by this circular arc.

7.Advance the window to the next 3 polyline vertices after the end of the circular arc and return to step 2.

Page 32: 1516 contouring

32

Error Calculation• To calculate error in fitting a circular arc ,

define distance of point Q (x1, y1) from the circle along a line passing through the center (x0, y0)

• q =

The distance from Q to the circular arc is d=q - r

201

201 )()( yyxx

Page 33: 1516 contouring

33

Conic Sections & Cubic Splines• Conic sections correspond to hyperbolas,

parabolas, and ellipses (2nd degree polynomials).

• Cubic splines correspond to 3rd degree polynomials.

• Conic sections and cubic splines allow more complex contours to be represented using fewer segments.

• Conic sections can be fit between three vertices in the polyline approximation.

Page 34: 1516 contouring

34

Conic section between three points

Page 35: 1516 contouring

35

Curve Approximation• Higher accuracy can be obtained by computing an

approximation that is not forced to pass through particular edge points.

• Approximation based methods use all the edge points to find a good fit (this is contrast to the previous methods that use only the interpolated edge points).

• Methods to approximate curves depend on the reliability with which edge points can be grouped into contours.(1) Least-squares regression can be used if it is certain that

the edge points grouped together belong to the same contour.

(2) Robust regression is more appropriate if there are some grouping errors.

(3) If grouping cannot be done easily using edge linking or following methods , then cluster analysis techniques like Hough transform are used

Page 36: 1516 contouring

36

Least-squares line fit• Linear regression fits a line to the edge points by

minimizing the sum of squares of the perpendicular distances of the edge points from the line being fit.

iii yxX 22 )cossin(

Page 37: 1516 contouring

37

Some math…(solution to the regression problem)

Page 38: 1516 contouring

38

Limitations

• It works well for cases where the noise follows a Gaussian distribution.

• It does not work well when there are outliers (edge points incorrectly linked to the contour) in the data (e.g., due to errors in edge linking ).

Page 39: 1516 contouring

39

Robust Regression • Outliers can pull the regression line far

away from its correct location.• Robust regression methods try various

subsets of the data points and choose the subset that provides the best fit.

Page 40: 1516 contouring

40

Least - Median Suares Regression• Algorithm:(assume that there are n data points and p parameters in the model)

(1) Choose p points at random from the set of n data points.

(2) Compute the fit of the model to the p points.(3) Compute the median of the square of the residuals.(4) Repeat until the median squared error is less than

some threshold, or take the best median error result after some number of runs.

• This algorithm can handle up to 50% outliers in the data set.

Page 41: 1516 contouring

41

Hough Transform

• Voting mechanism• Each point on the curve votes for

several combinations of parameters, the parameters that win a majority of votes are winners

• This technique assumes that a primitive edge detection is already performed on an image

Page 42: 1516 contouring

42

The technique• Consider the equation of a straight line y= mx +c• Rewriting the equation c= y – mx• Let us assume that m and c are variables of

interest and x and y are constants. The above equation represents a line in m-c space.

• A point (x,y) corresponds to line in m-c space• If there are n points lying on the straight line (in x-

y plane), then these will correspond to a family of lines in parameter space all passing through (m,c). This point gives parameters of original straight line

Page 43: 1516 contouring

43

Hough Transform Algorithm1. Quantize the parameter space appropriately2. Assume that each cell in the parameter space

is an accumulator. Initialize all cells to zero.3. For each point (x,y) in the image space ,

increment by 1 each of the accumulators that satisfy the equation

4. Maxima in the accumulator array correspond to the parameters of model instances

5. If the peak in the parameter space covers more than 1 accumulator then the centroid of the region gives an estimate of the parameters

Page 44: 1516 contouring

44

A Demonstration• The data is given on the left. The result of the Hough

transform is a bright orange box on the right of the figure (the Hough space) which is the result of a large number of counts for that accumulator.

Page 45: 1516 contouring

45

Limitations

• Size of discrete parameter space increases exponentially as number of parameters increases hence Hough transform may be computationally very inefficient for complex models

Page 46: 1516 contouring

46

Fourier Descriptors• Fourier coefficients are used to represent a closed

contour since they are periodic.• Boundary of an object is expressed as a sequence

of coordinates • We can represent each co ordinate pair as a

complex number so that • For a closed curve u(n) is periodic• DFT

• IDFT

)](),([)( nynxnu

1,....2,1,0),()()( Nnnjynxnu

1

0

/2 10,)()(N

k

Nknj Nnekanu

1

0

2

10,)(1)(N

n

Nnkj

NnenuN

ka

Page 47: 1516 contouring

47

Fourier Descriptors (contd..)

• The complex coefficients a(k) are called Fourier descriptors (FD) of the boundary

• Low resolution approximation• Only first M coefficients are used

1

0

2

10,)()(M

k

Nknj

Nnekanu

Page 48: 1516 contouring

48

SummaryContour Representation

Using InterpolationUsing Edge listUsing Curve fitting

Using ApproximationUsing RegressionUsing Hough Transform Using Fourier Descriptors

Page 49: 1516 contouring

49

References• Rafael C. Gonzalez, Digital Image

Processing• Ramesh C. Jain, et al., Machine Vision • Adrian Low, Introductory Computer Vision

and Image Processing

Page 50: 1516 contouring

50

Thank You !!