Polygonal Representation of Digital Curves

Approximating digital curves using polygonal approximations is required in many image processing applications [Kolesnikov & Franti, 2003, 2005; Lavallee & Szeliski, 1995; Leung, 1990; Mokhtarian & Mackworth, 1986; Prasad, et al., 2011; Prasad & Leung, 2010a, 2010b; Prasad & Leung, 2010; Prasad & Leung, 2012; Prasad, et al., 2011a]. Such representation is used for representing noisy digital curves in a more robust manner, reducing the computational resources required for processing and storing them, and for computing various geometrical properties of digital curves. Specifically, properties like curvature estimation, tangent estimation, detecting inflexion points, perimeter of the curves, etc., which are very sensitive to the digitization noise. Polygonal approximation is also useful in topological representation, segmentation and contour feature extraction in the applications of object detection, face detection, etc.

Then the deviation i d of a pixel (,) iii Px y e  from the line passing through the pair   1 , N PP is given as: Accordingly, the pixel with maximum deviation can be found. Let it be denoted as max P .
Then considering the pairs   1m a x , PP and   max , N PP , we find two new pixels from e using the concept in the equations (1) and (2). It is evident that the maximum deviation goes on decreasing as we choose newer pixels of maximum deviation between a pair. This process can be repeated till a certain condition (depending upon the method) is satisfied by all the line segments. This condition shall be referred to as the optimization goal for the ease of reference.
The condition used by L-RDP [Douglas & Peucker, 1973;Lowe, 1987;Ramer, 1972] is that for each line segment, the maximum deviation of the pixels contained in its corresponding edge segment is less than a certain tolerance value: where tol d is the chosen threshold.
In general, the value of tol d is chosen heuristically to be a few pixels and tol d functions as the control parameter. Now, we present the method to choose the value of tol d automatically using the characteristics of the line, such that the user does not need to specify the value of tol d [Prasad, et al., 2011a]. First we show that if a continuous line segment is digitized then the maximum distance between that digital line segment and the continuous line segment is bounded and can be computed analytically. Then, this bound can be used to choose the value of tol d adaptively.
We consider the effect of digitization on the slope of a line connecting two points (which may or may not be pixels) [Prasad, et al., 2011a]. Due to digitization in the case of images, a general point (,) Pxy is approximated by a pixel (,) Pxy  as follows: where round( ) x denotes the rounding of the value of real number x to its nearest integer. Let the slope of the line 12 PP (actual line) be denoted as m and the slope of the line 12 PP  (digital line) be denoted as m , where 1 P  and 2 P  are obtained by digitization of 1 P and 2 P using (4). See Fig. 1 The angular difference between the numeric tangent and the digital tangent is used as the estimate of the error. This angular difference is given as:

Global vs. local characteristics of line fit
It is expected that while fitting a polygon on a digital curve, which is effectively fitting a series of line segments on the digital curve, either we have to take very small local area in order to achieve high precision or we have to take a larger area in order to have a reliable and practically usable fit. This was formally stated and explained by Strauss in the context of Hough transform [Strauss, 1996;Strauss, 1999], "This duality could be set out as follows: as the shape detection precision increases, the reliability of the detection decreases. This seems to be due to the binary aspect of the vote in the classical Hough transform." While Strauss is right in pointing out the duality between the precision (quality of local fit) and reliability (quality of global fit), he is incorrect in attributing it to the nature of Hough transform. It can be shown using simple metrics, precision and reliability measures, that there is a perennial conflict in the quality of fit in the local scale (precision at the level of few pixels) and global scale (reliability at the level of complete curve) [Prasad & Leung, 2010c]. It is due to this reason, most absolute measures fail in quantifying the quality of fit properly [Carmona-Poyato, et al., 2011;Rosin, 1997].
Assuming that we are not bound by the limitation that the points used for representing the digital curve should be a subset of the digital curve, we just use least squares method to get the best line(s) fit for a digital curve and show that the precision and reliability measures are at conflict with each other. Suppose, for a digital curve with the sequence of pixels , we intend to fit a line 1 ax by   . Then, the coefficients of the line, a and b , can be determined by casting the problem of fitting into the following matrix equation [Acton, 1984]: , the superscript T denotes the transpose operation, and J is a column matrix containing M rows, whose every element is 1.

Precision
The precision of fitting can be modeled using the residue of the least squares method: It is evident that by choosing lesser number of pixels, i.e., reducing N , p  can be reduced and hence, the precision can be increased. It should be noted that with the decrease in the number of pixels, X and consequently B change, and thus the contribution from cos may vary. However, if continuous pixels are considered, the overall variance in X is reduced, and hence the impact of cos is also reduced. In effect, this means that fitting the line in a smaller local region is more precise than a large region.

Reliability
In this sub-section, we first present a quantitative measure of reliability that can be understood and compared with respect to the precision measure. Generally, for the reliability of a fit, the fit is expected to satisfy at least two conditions. First, the fit should be valid for a sufficiently large region (or in this case a long edge) and second, it should not be sensitive to occasional spurious large deviations in the edge. A combination of both these properties can be sought by defining a reliability parameter as follows: ,  represents the magnitude and max s is the maximum Euclidean distance between any two pair of pixels. Subscript r in r  denotes reliability. As before, lower the value of r  , higher the reliability.

Duality
As evident from (14) and (15), and the discussion between them, there is always a contradiction between precision and reliability. In order to increase the precision, we need to consider smaller regions for fitting, whereas for increasing the reliability, we need to consider larger regions for fitting (largest region being the region spanned by the connected edge pixels under consideration). Indeed the contradiction does not occur in ideal lines as shown in Fig. 2(a)-(d). It is also not an issue if the lines are in general smooth, so that the precision within a large region is already very high, such that reliability and precision are already sufficiently high and there is no practical need to increase the precision or reliability. Some such examples are presented in Fig. 2(e)-(g). This is illustrated in Fig. 3 and Table 1. However, if indeed an application calls for still higher precision, the reliability will have to be compromised and the duality comes into picture. Examples of more practical cases are shown in Fig. 2(h)-(p). In such cases, the duality comes into picture strongly and a balance has to be achieved in order to obtain a fit that is sufficiently reliable as well as precise.

Performance measures in the context of precision and reliability
We use various performance measures for comparing various algorithms.
1. Maximum deviation of any pixel on the edge from the fitted polygon ( max  ): In the context of a general line given by (12)

Integral square error (ISE):
This is the sum of squares of deviation of each pixel from the approximated polygon. It is given by Thus, effectively, ISE is also a precision measure.

Dimensionality reduction (DR) ratio or compression ratio (CR):
The compression ratio is the ratio of number of pixels in the digital curve ( N ) to the number of vertices of the polygonal approximation ( M ), CR N M  . Though this measure is not related to either precision or reliability, it is an important performance metric in practice. In addition to other metrics representing precision and/or reliability, a larger value of this is beneficial for reduction of data and computational resources. Instead of compression ratio, its reciprocal dimensionality reduction ratio can be used as a minimization metric (i.e. the lesser, the better).

Figure of merit (FOM)
Figure of merit is given by FOM=CR ISE . This is a maximization metric, i.e., larger value of FOM is preferred over a lower value. However, it is well known that FOM is biased towards ISE [Carmona-Poyato, et al., 2010]. For example, if the break points of a digital curve [Masood, 2008] are considered as the dominant points, the ISE is zero and inconsequent of the CR, FOM is infinity. If we intend to use a minimization metric, we may consider 1 WE =1/FOM [Marji & Siy, 2004]. It suffers with the same deficiency as FOM.

Fidelity, Efficiency and Merit
Researchers tried relative measures like fidelity, efficiency, merit to quantify the quality of fit [Carmona-Poyato, et al., 2011;Rosin, 1997]. In relative measures, a so-called optimal algorithm is considered as the reference for comparing the performance of the algorithm being tested. The method proposed by Perez and Vidal [Perez & Vidal, 1994] based on dynamic programming is generally used by the researchers as the reference algorithm. This is because it targets min   and min #  such that the fitting error is minimized for a certain number of points ( min   ) or the number of points for fitting is minimized for a given value of fitting error ( min #  ). It is logical that there is no way of determining an optimal value for the fixed number of points ( min   ) or the fixed value of fitting error ( min #  ), because such a value depends upon the nature of the digital curve for which polygonal approximation is sought.

Proposed performance measures
As seen in section 3.4, none of the existing methods cater for the global nature of the fit. Thus, the reliability measure is very important addition to the performance metrics of the polygonal approximation method. For the line segments (edges of the polygon), the precision and reliability measures are computed: where p   and r  are the precision and reliability measures, , and max s is the maximum Euclidean distance between any two pair of pixels [Prasad & Leung, 2010c]. Notation  represents the magnitude in the scalar case and the Euclidean norm in the case of vectors.
where j p   is the precision measure of the j th line segment, defined using (16).

Reliability measure for an edge
The net reliability measure of the digital curve is defined as follows: where j i X , j A , and max j s correspond to i X , A , and max s defined after (17) for the j th line segment.
3. Precision measure for a dataset of images Suppose a dataset contains L number of images, the number of edges in the l th image is l K , then, the precision measure for the dataset is:

Optimal polygonal representation of Perez and Vidal [Perez & Vidal, 1994]
The algorithm proposed by Perez and Vidal (PV) [Perez & Vidal, 1994] is by far the most popular algorithm used as a benchmark for comparing the performance of polygonal fitting algorithms. The reason for its popularity is twofold. For a given number of points NN   , where N is the number of pixels in the digital curve, it computes the optimal choice of N points from the digital curve such that some error metric is minimized. Since the error metric can be flexibly defined by a user, it is versatile in its use. Further, for the purpose of benchmarking, the designers of other algorithms can first perform the polygonal fitting using their own algorithms, obtain a value of N as obtained by their own algorithms, use this value of N in the algorithm by PV and simply compare the points obtained by their method against the optimal points obtained by PV.
Since PV can use any error metric to be minimized, it is interesting to note that we can either use the precision score or the reliability score as the error to be minimized. If precision score is used as the error function, PV attempts to fit segments such that all the line segments are of approximately the same length. If reliability score is used as the error function, PV attempts to fit segments that are combination of two types: first type are the small segment with small value of max d but with very small (close to zero) value of 1 i i   XA ; the second type are long segments with comparatively larger values of 1 i i   XA but significantly larger value of max d such that the reliability score is also small valued.
On the other hand, PV do not guarantee that the maximum deviation of the pixels in curve is within the upper limit of the error due to digitization. If the value of N is very large, it is likely that PV will fit the segments such that the maximum deviation is lesser than the upper bound. This means that the polygonal approximation will over fit and be sensitive to the error due to digitization. On the other hand, if the value of N is small, the maximum deviation of the fitted segments is larger than the upper bound, thus indicating underfitting. In essence, this means that using a fixed value of N or solving min- problem is not suitable for optimal polygonal approximation of the digital curves.

Lowe [Lowe, 1987] and Ramer-Douglas-Peucker [Douglas & Peucker, 1973; Ramer, 1972] (L-RDP method)
Lowe [Lowe, 1987] and Ramer-Douglas-Peucker [Douglas & Peucker, 1973;Ramer, 1972] is basically a splitting method in which the point of maximum deviation is found recursively till the maximum deviation of any edge pixel from the nearest line segment is less than a fixed value. Since this is a splitting algorithm, it begins with a very high value of max d , which reduces as the edge is split further. The algorithm stops at a point where the maximum deviation satisfies a minimum criterion. Thus, this algorithm focuses more on reliability and attempts to barely satisfy a precision requirement.
In the sense of the upper bound, this algorithm gives a mixed performance. For a few segments, the chosen threshold may be below the upper bound and the result is an overfitting for this segment. On the other hand, the chosen threshold may be above the upper bound for certain line segments, thus resulting in under-fitting for such segments.

Precision and reliability based optimization (PRO)
In this method, though the method of optimization is the same as the L-RDP method, the optimization goal is different than (3). Instead of (3), the optimization goal is: where, 0  is the chosen heuristic parameter. Since this method explicitly uses the precision and reliability measures as the optimization functions, this method is expected to perform well for both precision and reliability measures.
However, this method does not take into account the upper bound of the error due to digitization.

Break point supression method of Masood [Masood, 2008]
Masood begins with the sequence of the break points, i.e., the smallest set of line segments such that each pixel of the curve lies exactly on the line segments, which is considered as the initial set of dominant points. Then, he proceeds with recursively deleting one break point at a time such that removing it has a minimum impact in its immediate neighborhood and optimizing the locations of the dominant points for minimum precision score. Although the aim of optimization is to improve the global fit and thus indirectly improve the reliability, evidently, Masood's method is tailored for optimizing the precision and performs poorly in terms of reliability.
Since Masood begins with largest possible set of dominant points and removes the dominant points till a certain termination criterion is satisfied, if the termination criterion is not very relaxed, the maximum deviation is in general lesser than the upper bound. Thus, in essence, Masood's method is sensitive to the digitization effects and gives an unnecessarily close fit to the digital curve.

Dominent point detection method of Carmona-Poyato [Carmona-Poyato, et al., 2010]
Like Masood [Masood, 2008], Carmona also begins with the sequence of break points and the initial set of dominant points. However, unlike Masood, Carmona recursively deletes the dominant points with minimum impact on the global fit of the line segments. Thus, inherently Carmona-Poyato focuses more on reliability than on precision. It is evident in the results reported in [Carmona-Poyato, et al., 2010] that this method has a tendency to be lenient in the maximum allowable deviation in the favor of general shape representation for the whole curve.

Numerical examples
We consider the following methods for comparison:  [Masood, 2008]) using the termination criterion specified in [Masood, 2008], i.e., max 0.9   . 5. Carmona-Poyato (section 4.5, [Carmona-Poyato, et al., 2010]), using the termination condition specified in [Carmona-Poyato, et al., 2010], i.e., 0.4 i r  . Fig. 2 First, we consider L-RDP_max. The results are in the second row of Fig. 4. We see that L-RDP_max is able to avoid the fluctuations due to digitization and noise (in Fig. 4, see columns (g-p), row 2). In the meanwhile, it is able to retain good fit for snippets with important curvature changes, see columns (h,m,n,p), row 2 of Fig. 4. Conclusively, due to the consideration of the upper bound of digitization error, L-RDP_max considers the general features of the digital curve rather than concentrating on every single small scale feature of the curve.

Images of
The first observation is that L-RDP algorithms are very sensitive to the tolerance values. L-RDP0.5 algorithm gives a performance comparable to PRO0.2 and PRO0.4, both qualitatively (specifically note the columns (h,i,m,n) of Fig. 4) and quantitatively (see Table  2). A slight increase in tolerance from 0.5 to 1 changes the quality and performance parameters of the line fitting significantly, as evident in Fig. 4 and Table 2. The performance of L-RDP1 is closer to PRO0.6 and the performance of L-RDP1.5 is closer to L-RDP_max and PRO0.8. As the tolerance is increased further in L-RDP algorithms, the fitted line segments start losing information about the major curvature changes and represent the digital curves only crudely. Thus, though L-RDP2.0 provides significant dimensionality reduction (see DR in Table 2), it performs poorly for all the remaining performance parameters.
Next, we consider the results of PRO algorithms. It can be seen in the row PRO0.2 of Fig. 4 that it follows the digital curves very closely. As a consequence it is very sensitive to digitization and generates numerous small line segments to represent the curve, strongly evident in columns (e-i,k-p) of Fig. 4. Though definitely very reliable and precise, as evident Table 1, due to the tendency to fit the curves very closely, it performs poorly in dimensionality reduction (see DR values in Table 1). In the next set: PRO0.4-0.8, we see that these algorithms tend to follow the curvature of the digital curve, better than PRO0.2. We highlight the results in column (m) of Fig. 4. While PRO0.2 generated many line segment for the right side of the curve, PRO0.4-0.8 are more selective in fitting the line segments and fit the line segments focusing at the location of changes in curvature. Further, as the value of 0  increases from 0.4 to 0.8, the tendency to concentrate further on the general characteristics of the curve (rather than following every small scale feature of the curve) increases. This is significantly evident in the results in columns (h), (n), and (p) of Fig. 4. In the last PRO algorithm, PRO1.0, we see that rather than focusing on small features of the digital curve, these algorithms tend to follow the general characteristics of the digital curve on a relatively larger scale. Due to this reason, the results of PRO0.8-1.0 are closer to L-RDP_max. As a consequence of this characteristic, PRO0.8-1.0 and L-RDP_max have significantly better dimensionality reduction as compared to other PRO algorithms (see DR in Table 2).
With lower value of   Dataset However, due to the small length of the digital curves here and the fact that Carmona fits the polygonal approximation depending upon the length of the curve, in these figures with very small digital curves, it tends to fit the curves very closely (see columns (e,f,i,n,o) of Fig.  4), thus demonstrating better precision as well as reliability as compared to Masood. On the other hand for these images, L-RDP_max gives a performance in between Masood and Carmona-Poyato. This indicates that L-RDP_max avoids both under-fitting and over fitting.

Example of large closed curve
In this section, we consider an example of digital closed curve which is significantly large and contains 458 pixels. The digital curve is derived by scanning the image of dog from Figure 14 of [Masood, 2008] at 300 dpi, followed with blurring using Adobe Photoshop with a brush size of 2 pixels. Then the polygonal approximation obtained using various methods are presented in Fig. 5. As in section 5.1, the performance of L-RDP_max, L-RDP1.5, and PRO0.8 are similar. For this curve, the performance of Carmano-Poyato is also similar to L-RDP_max. Not only the number of vertices in the polygonal approximation for these cases are similar, the location of the vertices are also similar. L-RDP0.5 and PRO0.2 over fit the curve with numerous points. The quantitative performances are listed in Table 2.

Conclusion
Polygonal approximation of digital curves is an important step in many image processing applications. It is important that the fitted polygons are significantly smaller than the original curves, less sensitive to the digitization effect in the digital curves, and good representations of the curvature related properties of the digital curves. Thus, we need methods to deal with the digitization and consider both local and global properties of the fit.
First, we show that the maximum deviation of a digital curve obtained from a line segment has a definite upper bound. We show that this definite upper bound can be incorporated in a polygonal approximation method like L-RDP for making it parameter independent. Various results are shown to demonstrate the effectiveness of the parameter independent L-RDP method against digitization, dimensionality reduction, and retaining good global and local properties of the digital curve. In the future, we are hopeful that this error bound shall be incorporated in various recent and more sophisticated polygonal approximation and give a good performance boost to them, while making them free from heuristic choice of control parameters.
Second, we show that global and local properties of the fit are in contradiction with each other in general. We propose precision measure for measuring the local quality of fit and reliability measure for measuring the global quality of fit. Using them we show that better local fits are achieved by considering small edges of the polygons, while better global fit is achieved by making the edges of the polygon as long as possible. Further, we show that most contemporary measure of quality of fit are either directly related to precision or correspond to the local nature of fit. Since these measures are used in most contemporary algorithms, most of them concentrate on improving the local quality of the fit only. However, as demonstrated by the upper bound of the maximum deviation due to digitization, it may not be worth to reduce the precision below a certain level, since it is difficult to predict if the actual deviation is below the error bound due to digitization, some form of noise, or due to the nature of the curve. In our knowledge, only Carmona-Poyato includes reliability (though indirectly) in its algorithm [Carmona-Poyato, et al., 2010].
We also propose line fitting algorithm that specifically optimize the curves for increasing both precision and reliability simultaneously. We hope that these measures are paid attention to by the research community and better algorithms for polygonal fitting are developed, which provide good local as well as global fit. In the future, it shall be useful to further improve the design of the precision and reliability measures such that they are more representative of the quality of fit. Such improvements in design will also influence the quality of polygonal approximation achieved by the polygonal approximation methods.