A Linear Algorithm for Polygonal Approximations ... - Semantic Scholar

Report 0 Downloads 68 Views
A Linear Algorithm for Polygonal Approximations of Thick Curves Trung Nguyen Ecole Normale Superieure, 45 rue d’Ulm, 75005 Paris, France

Abstract. The concept of fuzzy segment was introduced in [2]. In this paper we suggest a notion of strict fuzzy segment and provide a linear algorithm for recognizing it thanks to a simple property of convex hull. A linear method to decompose a thick curve into strict fuzzy segments is also given. The quality of decomposition can be easily controlled by setting two threshold values: the maximum order and the minimum density of the fuzzy segments. The algorithm is fast, practical and multi-purpose.

1 Introduction Polygonal approximation of curves is an important task in contour analysis, shape recognition, digital cartography, and data compression. The problem can be informally stated as follows: given a digitized curve of N ≥ 2 ordered vertices1 , find M dominant vertices among them that define a sequence of segments which most closely resemble the original curve. A great deal of algorithms to resolve this problem have been proposed for over forty years. Most of them base on one of two approaches: dynamic programming and heuristics. One of the best known algorithms using dynamic programming was presented by Perez and Vidal [6]. They suggested the sum of the squared Euclidean distance as the global error criterion. The drawback of this algorithm is that its implementation requires O(M N 2 ) time and O(M N ) space. Salotti [8] improved this algorithm so that the complexity is close to O(N 2 ) by inserting the lower bound and employing the A* search algorithm instead of the dynamic programming one. Keeping the same ideas of Perez and Vidal, Kolesnikov and Fr¨anti [4] introduced a bounding corridor and iterated dynamic programming within it. The complexity has been significantly reduced ranging from O(N ) to O(N 2 ) but the solution does not remain optimal. While dynamic programming tries to give relatively optimal results, many algorithms using the heuristic approach are more favorable in real-time applications thanks to their rapidity. Relying on the Diophantine definition of discrete straight line and its arithmetical characteristics in [7], Debled-Rennesson and Reveill`es [1] gave a linear method for segmentation of curves into exact discrete lines. Their idea is to grow a segment incrementally as much as possible and the vertex that cannot be added to the 

1

This work is partially supported by the Geometrica project, INRIA Sophia Antipolis, France. Any opinions, findings, or conclusions expressed in this paper are those of the author and do not necessarily reflect the views of the Geometrica. The terms vertex and point will be used interchangeably through this paper.

A. Gagalowicz and W. Philips (Eds.): CAIP 2005, LNCS 3691, pp. 17–25, 2005. c Springer-Verlag Berlin Heidelberg 2005 

18

T. Nguyen

segment will be the beginning one of the next segment. This algorithm is distinguished from the others by its lossless data compression: the original curve can be reconstructed exactly from only the set of output segments and its first point. The number of segments unfortunately being large in particularly for irregular curves makes the algorithm less practical. In a slightly similar approach, Debled-Rennesson et al. [2] introduced the concept of fuzzy segment and provided a linear algorithm for decomposition of discrete curves into fuzzy segments. The algorithm is fast but not effective when applied to spiral curves. To the best of our knowledge, none of the algorithms of either approach reported in the literature have formally resolved the problem of approximation of thick curves as done in this paper. In many areas such as cartography or object recognition, we are interested in detecting the shape of roads, rivers, fingerprints, the jet of wind, etc. whose width is variable and considerable in comparison with their length. Obviously, one can simplify them to thin curves and then apply to them any available algorithm but we are likely to lose a valuable characteristic of curves. Another idea is to find the upper and lower borders of the object and do the approximation on them separately. The shape of the contour is however difficult to analyze. Moreover, no one can assure that the pairs of corresponding segments of the two borders are parallel – an important condition in cartography. In this paper, we extend the concept of fuzzy segment defined in [2] and provide a linear method to detect strict fuzzy segments. The idea we base on is a simple property of convex hull. Further, we present a fast algorithm to decompose a thick curve into thick fuzzy segments. We introduce the density parameter of fuzzy segments which, associated with the order parameter defined in [2], makes the quality of approximation better.

2 Discrete Lines and Strict Fuzzy Segments Many applications in Computer Vision are based on discrete points in Z2 . The integer set is however not strong enough even for the most basic properties in geometry, e.g. two non parallel discrete lines may intersect at no point or at an infinite number of points. In this paper, we base on the arithmetical definition of discrete line [7] on which many basic operators like translation, rotation, symmetry, calculation of distance from a point can be done in constant time. A great interest of this framework is that one may visit all points of a line in only linear time. Definition 1. [7] A discrete line, noted D(a, b, µ, ω), is the set of integer points (x, y) verifying the inequalities µ ≤ ax − by < µ + ω where a, b, µ, ω are integers. The real value ab with b = 0 and gcd(a, b) = 1 is the slope of the discrete line, µ is named lower bound and ω arithmetical thickness. We call D the naive line if the thickness ω verifies ω = max(|a|, |b|). D is the thick line if ω ≥ |a| + |b|. Definition 2. [2] Real straight lines ax − by = µ and ax − by = µ + ω − 1 are named the leaning lines of the discrete line D(a, b, µ, ω). An integer point of these lines is named a leaning point (see Fig. 1).

A Linear Algorithm for Polygonal Approximations of Thick Curves

19

x

y

y x

Fig. 1. A segment of the discrete line D(7, 12, 6, 40) whose equation is 6 ≤ 7x − 12y < 46, for x ∈ [−3, 20]. In grey are the leaning points.

Fig. 2. The points in squares constitute a strict , boundfuzzy segment with order d = 52 15 ing line D(4, −15, −22, 52) and density ϕ ≈ 78%

We can now state our definitions about strict fuzzy segments which may be independent with those of fuzzy segments in [2]. Definition 3. A nonempty set Sf of consecutive points of an object is a strict fuzzy segment with order d if: 1. There is a discrete line D(a, b, µ, ω) such that all points of Sf belong to D and ω d = max(|a|,|b|) 2. If there exits a discrete line D (a , b , µ , ω  ) containing all points of Sf , then ω max(|a |,|b |) ≥ d. The line D is said bounding for Sf . Definition 4. Let Sf be a strict fuzzy segment whose order is d, and whose abscissa n interval is [0, l - 1], the density ϕ of strict fuzzy segment Sf is the quotient ϕ = ld , where n is the number of points of Sf (see Fig. 2). Lemma 1. A set of points Sf is a strict fuzzy segment with bounding D(a, b, µ, ω) only if D possesses at least three leaning points. Among them, at least one is upper leaning point and one is lower leaning point. Corollary 1. Given a set of points Sf and its upper and lower hull, Sf is a strict fuzzy segment with bounding D if D has on its leaning lines at least two consecutive points of one hull and at least one point of the other hull. Moreover, this point is the farthest point (i.e. the Euclidean distance is maximal) from the leaning line through the two points.

3 Strict Fuzzy Segment Recognition From Corollary 1, the problem of detecting a strict fuzzy segment for an object is reduced to the problem of scanning triples of points, two consecutive points of the upper (resp. lower) envelope and one of the other envelope. We adopt the Rotating Caliper Algorithm [3] to calculate the order of the segment. Although width of a set, which is

20

T. Nguyen

defined as the minimum distance between the parallel lines of its support, is generally not order of the segment since the latter depends on slope of segment, the idea of Rotating Caliper Algorithm works well. Indeed, at each rotating caliper where the slope of segment is fixed, the point of minimum distance to the parallel line has also the smallest order. An algorithm for recognizing strict fuzzy segment is described as below.

Algorithm S TRICT F UZZY S EGMENT R ECOGNITION order ← ∞, F ← topL C ONSTRUCT C ONVEX H ULL  Rotating calipers on the upper envelope for i ← 0 to topU − 1 do maxLocal ← D ISTANCE(Low[F ], U pp[i], U pp[i + 1]) d ← D ISTANCE(Low[F − 1], U pp[i], U pp[i + 1]) while maxLocal < d and F > 0 do maxLocal ← d F ←F −1 d ← D ISTANCE(Low[F − 1], U pp[i], U pp[i + 1]) if order > maxLocal then order ← maxLocal a ← U pp[i + 1].y − U pp[i].y b ← U pp[i + 1].x − U pp[i].x µ ← a × U pp[i].x − b × U pp[i].y ω ← a × Low[F ].x − b × Low[F ].y − µ + 1 l ← U pp[topU ].x − U pp[0].x + 1 n density = l×order  Rotating calipers on the lower envelope (same as the above with U pp and Low exchanged) return D(a, b, µ, ω), order and density

For the construction of convex hull, we can employ any algorithm which computes it correctly. In this paper, we recommend the algorithm of Melkman [5] for its simple implementation. The construction takes O(n) time when the points of object are in order and O(n log n) times when applied to the general case. In order that our paper is self-contained, the pseudo-code of Melkman algorithm is given below with a minor modification that we make use of two stacks to store the upper and lower envelope separately instead of one deque in the author’s paper. The function D ISTANCE takes three vertices as arguments and returns the distance from the first vertex to the line passing through two last ones. The function I S L EFT in the Melkman algorithm below feeds the same arguments but returns the predicate whether the first point is strictly on the left of the line taking into account its direction. Correctness. The correctness of our algorithm comes from Corollary 1 and Rotating Caliper Algorithm.

A Linear Algorithm for Polygonal Approximations of Thick Curves

21

Algorithm M ELKMAN ’ S C ONVEX H ULL C ONSTRUCTION for each M ∈ Sf do if not (I S L EFT(M, Low[topL − 1], Low[topL]) and I S L EFT(M, U pp[topU ], U pp[topU − 1])) then  Get the rightmost tangent on the upper convex while not I S L EFT(M, U pp[topU ], U pp[topU − 1]) do topU ← topU − 1 topU ← topU + 1 U pp[topU ] ← M  Get the rightmost tangent on the lower convex while not I S L EFT(M, Low[topL − 1], Low[topL]) do topL ← topL − 1 topL ← topL + 1 Low[topL] ← M return U pp and Low Complexity. The main for loop will run topU times which is smaller than N . The assignment operations, the if condition and the functions I S L EFT and D ISTANCE can be computed in constant time. After each iteration of the while loop, the value of F is decreased by one. The number of passes through this loop is therefore smaller than topL in total. For the case where all of the points are ordered, Melkman’s construction works in linear time. Hence, the complexity of our algorithm is O(N ) time, where N is the number of vertices. In the implementation, we use two arrays U pp and Low of size N for storing the coordinates of the convex hull. Thus, the total memory requirement of the algorithm is proportional to 2N , which is linear. Remark. Rotating Caliper Theorem applies for the computational geometry where the distance is in the Euclidean space. In the discrete geometry, the distance of a point (x0 , y0 ) to the discrete line D(a, b, µ, ω) is alternatively defined in [1] as ax0 − by0 − µ. This number is only the result of multiplying the distance in the Euclidean space above by (a2 + b2 ). In Algorithm S TRICT F UZZY S EGMENT R ECOGNITION, we fix the line passing through a couple of convex points, i.e. the value of a and b are unchanged, when compare the distances. Therefore, our algorithm works in the discrete geometry as well. Moreover, it also allows to deal with the sets of disconnected points that do occur in the real-world problems.

4 Strict Fuzzy Segmentation In this section, we present a technique for approximating an object into strict fuzzy segments. We introduce two thresholds, the maximum order and the minimum density, for all decomposed segments. Increasing the maximum permitted order makes the number of segments reduce but it also decreases the quality of segmentation. This trade-off can be under control by setting the appropriate value for the minimum density threshold. Our idea of segmentation is then very simple: try to prolong the current segment as much as possible until it violates the given thresholds. This idea can be best implemented with the dichotomy algorithm. Fixing the first point of the object of N vertices, we wish to look for the last possible point that the points between them constitute a strict fuzzy segment. This segment must satisfy our thresholds and have the possibly

22

T. Nguyen

maximal order. Firstly, the algorithm S TRICT F UZZY S EGMENT R ECOGNITION is applied for the whole object. If it returns the positive answer, we are done; otherwise, the algorithm will check for the first half set [0, N/2]2 If again this subset is not a satisfying segment, we try for a smaller set [0, N/4]; if not, we extend the set to [0, 3N/4]. After each step, we divide the interval by two and maintain the segment which satisfies simultaneously the two thresholds and has the maximum order by far. Continue halving the search interval in this way until the order of the segment reaches the threshold or the interval is a unit. In the former case, we report the current segment as result; in the latter case, the output segment is the one that we have recorded before. We repeat this procedure again and the ending point of the current segment will start the next segment. In the algorithm below, the variables f irst and last indicate the expected first and last points of the current segment, maxOrder and minDensity are two given thresholds. The function E XTRACT M ONOTONE S ET takes the argument f irst and returns the maximal value of last such that the set of points [f irst, last] is horizontally or vertically monotone. The function S TRICT F UZZY S EGMENT R ECOGNITION described in the previous section returns the characteristics of the strict fuzzy segment for the subset [f irst, last] of the object O. Algorithm S TRICT F UZZY S EGMENTATION Segs ← ∅, f irst ← 0 while f irst < N do last ← E XTRACT M ONOTONE S ET(O, f irst) interval ← last − f irst curOrder ← 0 while interval > 0 and curOrder = minOrder do S TRICT F UZZY S EGMENT R ECOGNITION(O, f irst, last) if curOrder < order ≤ maxOrder and density ≤ minDensity then curOrder ← order curD ← D(a, b, µ, ω) split ← last interval ← interval/2 if order < minOrder then last ← last + interval else if order > minOrder then last ← last − interval Segs ← Segs ∪ {curD} f irst ← split return Segs

Correctness. The dichotomy algorithm works well when the orders of segments are sorted, that is verified by the following lemma. The algorithm of segmentation always terminates and returns the correct answer since the unit set of two vertices defines an ideal fuzzy segment whose order is 0 and density is 1. 2

To simplify the writing, we note [a, b](a ≤ b) the subset of points from the point numbered a to the point numbered b according to their orders in the set Sf .

A Linear Algorithm for Polygonal Approximations of Thick Curves

23

Lemma 2. Let A and B be two nonempty sets of points and A ⊆ B. Suppose that A and B are strict fuzzy segments with orders dA and dB respectively, then dA ≤ dB . Complexity. Let us show that the algorithm S TRICT F UZZY S EGMENTATION decomposes an object O into a set of strict fuzzy segments in linear time. The trick lies in the implementation of two functions E XTRACT M ONOTONE S ET and S TRICT F UZZY S EGMENT R ECOGNITION. For the first function, we make use of four variables for each point P of O. These variables store respectively the maximal lengths that vertically decreased, horizontally decreased, vertically increased and horizontally increased sets starting from P may have. They can be backwards determined in linear time at the initialization of the algorithm. The function E XTRACT M ONOTONE S ET is only a simple calculation on them, therefore not costly. For the second function, we make a minor modification to the construction of convex hull thanks to the online property in Melkman algorithm. Instead of computing the new stacks U pp and Low from the first point for each halving of interval, we try to reuse them as much as possible. For the first case where last ← last + interval, we keep the old stacks and store them in memory. The construction may be continued at the point in last + 1. The reason to store these stacks in memory is that all expected last points in the following steps are on the right of the current last point last; so we may reuse them further. For the other case where last is decreased by interval, we restore the stacks from memory that we last saved. A simple deduction can show that these stacks in fact stored the subsets [f irst, last − 2 × interval]. The construction thus may continue from the top point on these stacks. In either case, the number of points needed to be calculated is smaller than interval. The function S TRICT F UZZY S EGMENT R ECOGNITION therefore takes no more than O(N ) time in total. Hence, the complexity of our algorithm is linear. In addition to the memory required by the function S TRICT F UZZY S EGMENT R ECOGNITION, we only use two stacks of size N for memorizing. Thus the space complexity is O(N ) as well. Approximation of thick curves into thick segments. Our algorithm may also be performed to decompose thick curves into thick segments. The output segments vary in thickness. Figure 3 illustrate the results of decomposition when we apply the algorithm S TRICT F UZZY S EGMENTATION to a digitized route of 55705 vertices with different values of the maximum order and the minimum density. In our examples, the algorithm produces 9 and 12 segments respectively. Thus the compression ratio is about 3–5 × 10−3 %, given a segment takes two times as much space in memory as a point does. Along with the fact that one may visit all points of a line in linear time, we have constructed a model of compression/decompression in linear time. Choice of parameters. The maximum order should not be smaller than the largest thickness of the curve, otherwise no solution will be found. Increasing the value of maxOrder allows to minimize the number of detected segments. In return, it also reduces the quality of segmentation in the sense that many points of the segments do not belong to the object. We call them the false points. The parameter minDensity therefore is added to restrict the ratio of false points in each detected segment. The experimental evaluations show that the choice of this parameter does not affect the running

24

T. Nguyen

Fig. 3. Results of polygonal approximation of a thick curve of 55708 points. L EFT : max order = 65, min density = 0.4,  M = 9. R IGHT : max order = 60, min density = 0.7  M = 12.

Fig. 4. Results of polygonal approximation of a thick curve on a snake. L EFT : max order = 60, min density = 0.6,  M = 14. R IGHT : max order = 75, min density = 0.4  M = 10. Photo Eastern Garter Snake courtesy of John White and CalPhotos.

Fig. 5. Results of polygonal approximation of thin curves

A Linear Algorithm for Polygonal Approximations of Thick Curves

25

time. Maintaining a high value of minimum density can lead to a high quality segmentation but a large number of segments will be reported. Too small values of minimum density may change the geometrical structures of output segments (compare in Fig. 4). When the minimum density is set to 0, all fuzzy segments are strict, thus the number of segments is minimal (min-# problem). On the other hand, when minOrder = 1, no false point is allowed and the output retains only exact segments. In this case, the algorithm has the same property of lossless data compression as [1]. At last, the algorithm may apply for thin curves which is shown in Fig. 5.

5 Conclusion We have presented a linear algorithm of strict fuzzy segmentation using a simple property of convex hull. The trade-off between the number of segments and the quality of segmentation can be regulated by the selection of the maximum order and the minimum density. Our algorithm is multi-purpose: it can be used to decompose a thick or thin curve into strict fuzzy segments or exact segments. It works in both geometries, computational and discrete. The points may be connected or not making our algorithm more practical. This work opens many perspectives for studying polygonal approximation of noisy thick curves in 3D space.

Acknowledgements The author wishes to express his gratitude to Isabelle Debled-Rennesson for the helpful discussions in the course of the preparation of this paper. The test sets illustrated in Fig. 5 were provided by her and Pasi Fr¨anti. Many thanks to John White for giving permission to use his nice photo.

References 1. I. Debled-Rennesson and J.-P. Reveill`es, A linear algorithm for segmentation of digital curves, International Journal of Pattern Recognition and Artificial Intelligence, vol. 9, pp. 635-662, 1995. 2. I. Debled-Rennesson, J.-L. Remy and J. Rouyer, Segmentation of discrete curves into fuzzy segments, Electronic Notes in Discrete Mathematics, vol. 12, 2003. 3. M. E. Houle, and G. T. Toussaint, Computing the width of a set, IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 10 , Issue 5 , pp. 761-765, 1988. 4. A. Kolesnikov and P. Fr¨anti, Reduced-search dynamic programming for approximation of polygonal curves, Pattern Recognition Letters, 24 (14), 2243-2254, 2003. 5. A. Melkman, On-line construction of the convex hull of a simple polyline, Information Processing Letters, vol. 25, pp. 11-12, 1987. 6. J.-C. Perez and E. Vidal, Optimum polygonal approximation of digitized curves, Pattern Recognition Letters, vol. 15, pp. 743-750, 1994. 7. J.-P. Reveill`es, G´eom´etrie discr`ete, calcul en nombres entiers et algorithmique, Th`ese d’Etat, Universit´e Louis Pasteur, Strasbourg, 1991. 8. M. Salotti, An efficient algorithm for the optimal polygonal approximation of digitized curves, Pattern Recognition Letters, vol. 22, pp. 215-221, 2001.