17
International Journal of Computer Mathematics Vol. 87, No. 8, July 2010, 1736–1751 Vectorizing outlines of generic shapes by cubic spline using simulated annealing Muhammad Sarfraz* Department of Information Science, Adeleyah Campus, Kuwait University, Safat, Kuwait (Received 29 May 2008; revised version received 23 July 2008; accepted 29 August 2008 ) A global optimization technique is proposed for the outline capture of generic shapes. This is inspired by a global optimization algorithm based on simulated annealing (SA) by Kirkpatrick et al. [S. Kirkpatrick, C.D. Gelatt Jr., and M.P.Vecchi, Optimization by simulated annealing, Science 220(4598) (1983), pp. 671– 680]. The proposed work, in this paper, is concerned with an efficient technique of vectorizing outlines of generic shapes. It is mainly achieved by curve fitting with a generalized cubic spline. The overall technique has various phases including extracting outlines of images, detecting corner points from the detected outline, curve fitting and addition of extra knot points if needed. The last two phases make a significant contribution by making the technique automated. It uses the idea of SA to optimize the shape parameters in the description of the generalized cubic spline introduced. The idea of SA has been used to optimize the shape parameters in the description of the generalized cubic spline introduced. The spline method ultimately produces optimal results for the approximate vectorization of the digital contour obtained from the generic shapes. The process is fully automatic and requires no human intervention. Implementation details are sufficiently discussed. Some numerical and pictorial results are also demonstrated to support the proposed technique. Keywords: generic shapes; curve fitting; cubic spline; simulated annealing; knot insertion 1. Introduction Capturing and vectorizing outlines of images is one of the important problems of computer graphics, vision and imaging. Various mathematical and computational phases are involved in the whole process. This is usually done by computing a curve close to the data point set [7,12,18,21,22]. Computationally economical solution is an ultimate objective to achieve the objective of vectorizing outlines of planar objects. The representation of planar objects in terms of curves has many advantages. For example, scaling, shearing, translation, rotation and clipping operations can be performed without any difficulty. Although a good amount of work has been done in this area [6,11,13,19,27,28,30], it is still desired to proceed further to explore more advanced and interactive strategies. Most of the up-to-date research has tackled this kind of problem by curve subdivision or curve segmentation. Curve segmentation is advantageous in that it gives a rough geometry of the shape. Approaches *Email: [email protected] ISSN 0020-7160 print/ISSN 1029-0265 online © 2010 Taylor & Francis DOI: 10.1080/00207160802452519 http://www.informaworld.com

Vectorizing outlines of generic shapes by cubic spline using simulated annealing

Embed Size (px)

Citation preview

Page 1: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer MathematicsVol. 87, No. 8, July 2010, 1736–1751

Vectorizing outlines of generic shapes by cubic spline usingsimulated annealing

Muhammad Sarfraz*

Department of Information Science, Adeleyah Campus, Kuwait University, Safat, Kuwait

(Received 29 May 2008; revised version received 23 July 2008; accepted 29 August 2008)

A global optimization technique is proposed for the outline capture of generic shapes. This is inspired bya global optimization algorithm based on simulated annealing (SA) by Kirkpatrick et al. [S. Kirkpatrick,C.D. Gelatt Jr., and M.P. Vecchi, Optimization by simulated annealing, Science 220(4598) (1983), pp. 671–680]. The proposed work, in this paper, is concerned with an efficient technique of vectorizing outlines ofgeneric shapes. It is mainly achieved by curve fitting with a generalized cubic spline. The overall techniquehas various phases including extracting outlines of images, detecting corner points from the detectedoutline, curve fitting and addition of extra knot points if needed. The last two phases make a significantcontribution by making the technique automated. It uses the idea of SA to optimize the shape parametersin the description of the generalized cubic spline introduced. The idea of SA has been used to optimizethe shape parameters in the description of the generalized cubic spline introduced. The spline methodultimately produces optimal results for the approximate vectorization of the digital contour obtained fromthe generic shapes. The process is fully automatic and requires no human intervention. Implementationdetails are sufficiently discussed. Some numerical and pictorial results are also demonstrated to supportthe proposed technique.

Keywords: generic shapes; curve fitting; cubic spline; simulated annealing; knot insertion

1. Introduction

Capturing and vectorizing outlines of images is one of the important problems of computergraphics, vision and imaging. Various mathematical and computational phases are involvedin the whole process. This is usually done by computing a curve close to the data pointset [7,12,18,21,22]. Computationally economical solution is an ultimate objective to achievethe objective of vectorizing outlines of planar objects.

The representation of planar objects in terms of curves has many advantages. For example,scaling, shearing, translation, rotation and clipping operations can be performed without anydifficulty. Although a good amount of work has been done in this area [6,11,13,19,27,28,30], itis still desired to proceed further to explore more advanced and interactive strategies. Most of theup-to-date research has tackled this kind of problem by curve subdivision or curve segmentation.Curve segmentation is advantageous in that it gives a rough geometry of the shape. Approaches

*Email: [email protected]

ISSN 0020-7160 print/ISSN 1029-0265 online© 2010 Taylor & FrancisDOI: 10.1080/00207160802452519http://www.informaworld.com

Page 2: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1737

used to achieve this task are polygonal approximations [6,20,27], circular arc approximations[1,11,19,23,24] and approximations using cubics or higher-order spline functions [5,12,28].

A non-parametric dominant point detection algorithm is proposed in [20], it uses the dominantpoints for polygonization of digital curves. The problem with polygonal approximation is that theseapproaches are rarely used for shape analysis [6,27]. A combination of line segments and circulararcs for object approximation is used in [1,24]. A scheme to construct a curvature continuousconic spline is proposed in [19]. This approach presented the conic spline curve fitting andfairing algorithm using conic arc scaling. The smoothing is done by removing unwanted curvatureextrema. Similar algorithms for data fitting by arc spline curves are presented in [23]. A methodfor segmentation of curves into line segments and circular arcs by using types of breakpointsis proposed in [11]. Advantage of this technique is that it is threshold free and transformationinvariant. Five categories of breakpoints have been defined. The line and conic segmentation andmerging are based on these breakpoints.

Least square fitting is mostly adopted in approximations, which uses splines and higher-orderpolynomials. Some approaches are based on active contour models known as snakes. This tech-nique is also based on parameterization. Enhancement to the scheme by adjusting both numberand positions of control points of the active spline curve is shown in [28]. This scheme is basedon the curve approximation using iterative optimization with B-spline curve by squared distanceminimization.

Another way, other than parametric form, is to use implicit form of the polynomial. Curve recon-struction problem is solved by approximating the point clouds using implicit B-spline curve [13].The authors have used trust region algorithm in optimization theory as minimization heuristics.Techniques described for fitting implicitly defined algebraic spline curves and surfaces to scat-tered data by simultaneously approximating points and associated normal vectors are proposedin [10,15,29].

This work is inspired by a global optimization algorithm based on simulated annealing (SA)by Kirkpatrick et al. [12]. It motivates the author to a global optimization technique proposed forthe outline capture of the planar images. In this paper, the data point set represents any genericshape whose outline is required to be captured. We present an iterative process to achieve ourobjective. The algorithm comprises of various phases to achieve the target. First of all, it finds thecontour of the greyscaled bitmap image. Secondly, it detects corners. These phases are consideredas preprocessing steps. The next phase detects the corner points on the digital contour of thegeneric shape under consideration. The idea of SA is then used to fit a generalized cubic splinethat passes through the corner points. It optimizes the shape parameters in the description of thegeneralized cubic spline to provide an approximation to the digital curve.

In most of the cases, the corner points are not enough to approximate the digital object andhence some more points are also needed. These points are known as break points or knots, asthey are used to break a segment for better approximation. In the fourth phase of the proposedalgorithm, for each iteration, we are inserting a point as knot in every piece in a manner thatthe distance, d, of the computed point on the spline curve and its corresponding contour point isgreater than a threshold ε. This is computationally very efficient compared with computing leastsquare distance or least mean square error for all the data points. We stop the iteration when all d’sare less than ε. This step differentiates the work achieved in [12]. The spline method ultimatelyproduces optimal results for the approximate vectorization of the digital contour obtained fromthe generic shapes. It provides an optimal fit with an efficient computation cost as far as curvefitting is concerned.

The organization of the paper is as follows, Section 2 discusses about the preprocessing stepswhich includes finding the boundary of planar object and corner detection algorithm for finding thesignificant points. Section 3 is about the interpolant form of cubic spline curves and computationof its associated tangents. The process of SA is explained in Section 4. Overall methodology of

Page 3: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1738 M. Sarfraz

curve fitting is explained in Section 5, which includes the idea of knot insertion as well as thealgorithm design for the proposed vectroization scheme. Demonstration of the proposed schemeis made in Section 6. The paper is concluded in Section 7.

2. Preprocessing

The proposed scheme initially starts first finding the boundary of the generic shape and then usingthe output to find the corner points or the significant points. Forthcoming Sections 2.1 and 2.2will explain these phases.

2.1 Finding boundary of generic shapes

The image of the generic shape can be acquired either by scanning or by some other means. Thequality of scanned images is dependent upon factors such as paper quality and scanning resolution.With a better resolution and paper quality, one can achieve a better image.

The aim of boundary detection is to produce an object’s shape in graphical or non-scalar repre-sentation. Chain codes [14,16,17,26] are the most widely used representations. Other well-knownrepresentations are syntactic techniques, boundary approximations and scale-space techniques.The benefit of using chain code is that it gives the direction of edges. The boundary points areselected as contour points based on their corner strength and fluctuations.

Chain codes were initially proposed by Freeman [14,16,17,26]. The methodology adopted todetect the boundary is by encoding the shape boundary as a sequence of connected line segments ofspecified length and direction. The direction of a segment is coded using either 4-connected or 8-connected schemes. In both schemes, initially a point is selected using either horizontal or verticalscan. After this, the 4-connected or 8-connected component algorithm is applied. Both algorithmswork in intensive stack formulation. In the case of 4-connected schemes, four neighbouring pointsare analysed. These points are pixel positions that are right, left, above and below the current pixel.The second method is a little more complex. In this method, the set of neighbouring positions tobe tested includes the four diagonal pixels as well. The point set obtained after this step is knownas contour of the object.

We simply convert a greyscaled image to binary after normalizing the intensity in the range [0,1]. The image is then converted to binary at a specified threshold. If the threshold is 0.4, a pixel ofintensity less than 0.4 is a white pixel and others are black pixels. Outline extraction from a binaryimage is a simple procedure. Any pixel with a pixel value 0 (black) is a boundary point if anyof its four neighbours has a pixel value 1 (white). The four neighbouring pixels are upper, lower,left and right pixels. This procedure will extract all the boundary points (inner or outer boundarypoints) from the binary image. At this point it is difficult to distinguish that which boundary pointbelongs to which boundary loop (in case of more than one boundary loops) and also the sequenceof boundary points (clockwise) around a loop is unknown.

To arrange the extracted boundary points in a sequence (clockwise direction), a boundarytracing is performed, starting from the left-top boundary pixel. The algorithm [4] for boundarytracing is as follows:

(1) Search the top-left boundary point; this point P0 has the minimum column and row valueof all the boundary points. Point P0 is the starting point of the boundary tracing. Define avariable dir using Freeman’s chain code [14] as shown in Figure 1. It stores the directionof the previous move along the boundary from previous point to the current point. Assigndir = 3.

Page 4: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1739

Figure 1. Freeman’s chain code.

Figure 2. Neighbourhood search sequence.

(2) Search the 3 × 3 neighbourhood of the current point in an anti-clockwise direction as shownin Figure 2, starting the neighbourhood search in the direction given below:(a) (dir + 7) mod 8 if dir is even.(b) (dir + 6) mod 8 if dir is odd.Update the dir value as per the new point found.

(3) If the current boundary point Pn is equal to the point P0 then stop. Otherwise repeat Step 2.(4) The detected boundary points are represented by points P0, . . . , Pn−1. This makes a one loop

of boundary points.(5) Delete the detected boundary points P0, . . . , Pn−1 from the list of extracted boundary points

and repeat Steps 1–4 for other boundary loops till all boundary loops have been traced.

Demonstration of the method can be seen in Figure 3(b) which is the contour of the bitmapimage shown in Figure 3(a).

2.2 Detecting corner points

Corners in digital images give important clues for the shape representation and analysis. Generallyan object’s information can be represented in terms of its corners, which play a very vital role in

Figure 3. Preprocessing steps: (a) original image, (b) outline of the image and (c) corner points achieved.

Page 5: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1740 M. Sarfraz

Figure 4. Corner point detection demonstration. (a) First pass: test p for candidate corner point and (b) second pass:discard non-maxima points.

object recognition, shape representation and image interpretation [3,20]. These are the points thatpartition the boundary into various segments. The strategy of getting these points is based on themethod proposed in [3]. The details of this procedure are as follows.

The corner detector used assess the curvature of points and picks those with high values. Thealgorithm has two passes. A variable triangle (p−, p, p+) is inscribed in the first pass as shownin Figure 4(a). This is constrained by the following rules:

d2min ≤ |p − p+|2 ≤ d2

max, (1)

d2min ≤ |p − p−|2 ≤ d2

max, (2)

α ≤ αmax, (3)

where |p − p+| = |a| = a is the distance between p and p+ and similarly |p − p−| = |b| = b

is the distance between p and p−. Then |p+ − p−| = |c| = c is the distance between p+ and p−.The opening angle of the triangle α is computed as follows:

α = cos−1

(a2 + b2 − c2

2ab

).

Adjacent points can be detected in the first pass. The second pass is used to discard the non-maxima points. A candidate point p is discarded if it has a sharper valid neighbour pv , suchthat α(p) > α(pv). The validity of the candidate point in the neighbourhood of p is legitimate if|p − pv|2 ≤ d2

min or if it is adjacent to p. This is depicted in Figure 4(b). The demonstration ofthe algorithm is made on Figure 3(b). The corner points of the image are shown in Figure 3(c).

3. Curve fitting with cubic spline

The motive of finding the corner points, in Section 2.2, was to divide the contour into pieces.Each piece contains the data points in between two subsequent corners inclusive. This meansthat if there are m corner points cp1, cp2, . . . , cpm then there will be m pieces pi1, pi2, . . . , pim.We treat each piece separately and fit the spline [8,12] to it. First piece includes all the contour

Page 6: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1741

points between cp1 and cp2 inclusive. Second piece contains all the contour points between cp2

and cp3 inclusive. Consequently, the mth piece contains all the contour points between cpm andcp1 inclusive. In general, the ith piece contains all the data points between cpi and cpi+1 inclusive.This is represented in Figure 4.

After breaking the contour of the image into different pieces, we fit the spline curve to eachpiece. For this purpose we have used piecewise parametric cubic spline interpolant. The splineformulation globally is C1 continuous.

3.1 Cubic spline interpolant

The cubic spline is defined as follows:

P(t) = (1 − θ)3Fi + 3θ(1 − θ)2Vi + 3θ2(1 − θ)Wi + θ3Fi+1, (4)

where

θ |[ti ,ti+1)(t) = (t − ti)

hi

and

Vi = Fi + hiDi

3, Wi = Fi+1 − hiDi+1

3.

Equation (4) can be rewritten as

P |(ti ,ti+1)(t) = R0,i (t)Fi + R1,i (t)Vi + R2,i (t) + R3,i (t)Fi+1, (5)

where

R0,i (t) = (1 − t)3,

R1,i (t) = 3t (1 − t)2,

R2,i (t) = 3t2(1 − t),

R3,i (t) = t3.

(6)

The functions Rj,i, j = 0, 1, 2, 3 are Bernstein–Bézier-like basis functions, such that

3∑j=0

Rj,i(t) = 1. (7)

From the Bernstein–Bézier theory it follows that the curve segment P |[ti ,ti+1] lies in the convexhull of the control points {Fi, Vi, Wi, Fi+1} and is variation diminishing with respect to the controlpolygon joining these points.

To get the control points {Fi, Vi, Wi, Fi+1}, we make use of a Bernstein–Bézier representation,where we can impose the Hermite interpolation conditions:

P(ti) = Fi and P ′(ti) = Di, i = 0, 1, . . . , n, (8)

where Fi and Fi+1 are the corner points of ith piece. Di and Di+1 are the corresponding tangentsat the corner points.

To construct the parametric C1 cubic spline interpolant on the interval [t0, tn], we have Fi ∈Rm, i = 0, 1, . . . , n, as interpolation data, at knots ti , i = 0, 1, . . . , n. The derivatives Di ∈ Rm

Page 7: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1742 M. Sarfraz

can be found by the imposition of C1 constraints on the piecewise cubic form. The C1 constraintscan be written as

P ′(t+i ) = P ′(t−i ). (9)

The tangent vectors are calculated as follows:

D0 = 2(P1 − P0) − (P2 − P0)

2,

Di = ai(Pi − Pi−1) + (1 − ai)(Pi+1 − Pi),

Dn = 2(Pn − Pn−1) − (Pn − Pn−2)

2,

(10)

where

ai = ‖Pi+1 − Pi‖‖Pi+1 − Pi‖ + ‖Pi − Pi−1‖ .

Since, the objective of the paper is to come up with an optimal technique which can provide adecent curve fit to the digital data. Therefore, the interest would be to compute the curve in sucha way that the sum-squared error of the computed curve with the actual curve (digitized contour)is minimized. Mathematically, the sum-squared distance is given by

Si =mi∑

j=1

[Pi(ui,j ) − Pi,j ]2, ti,j ∈ [ti , ti+1], i = 0, 1, . . . , n − 1, (11)

where

Pi,j = (xi,j , yi,j ), j = 1, 2, . . . , mi (12)

are the data points of the ith segment on the digitized contour. The parameterization over t’s isin accordance with the chord length parameterization. Thus, the curve fitted in this way will be acandidate of best fit.

3.2 Generalized cubic spline interpolant

The curve fitted in Section 3.1 is a candidate of best fit, but it may not be a desired fit. This leadsto the need of introducing some shape parameters in the description of the cubic spline. Thissection deals with the generalized form of cubic spline. It introduces two parameters v and w inthe description of cubic spline defined as follows:

P(t) = (1 − θ)3Fi + 3θ(1 − θ)2Vi + 3θ2(1 − θ)Wi + θ3Fi+1, (13)

where

Vi = Fi + hiviDi, Wi = Fi+1 − hiwiDi+1. (14)

Obviously, the parameters’ vi’s and wi’s, when equal to 1/3, provide the special case of cubicspline in Section 3.1. Otherwise, these parameters can be used to loosen or tighten the curve. Thispaper proposes an evolutionary technique, namely SA, to optimize these parameters so that thecurve fitted is optimal.

Page 8: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1743

4. Simulated annealing

SA [2,4] is a global optimization method based on the Monte Carlo method. It works on the analogyof the energy in an n-body system where the material is cooled to lower temperatures graduallyto result in a perfect crystal structure. The perfect crystal structure is attained by having minimumenergy in the material. This analogy translates to the optimization done in SA in finding a solutionthat has the lowest objective function value. The solution space is all the possible solutions. Thecurrent solution is the present state of the material. The algorithm iteratively tries to change thestate of the material and check whether it has improved. The material’s state is changed slightly tofind a neighbouring state, i.e. a close solution value in the solution space. It is possible that all theneighbouring states of current states are worse solutions. The algorithm allows going to a worsestate with a certain probability. This probability decreases as the algorithm iterations proceed.Finally, it only allows a change in state if it is strictly better than the current solution. Details ofSA theory can be found in [2,4] and an example applet can be seen in [25]. A detailed descriptionof the mapping of the SA technique on our problem is given in the next section.

5. Proposed approach for vectorization

The proposed approach to the curve problem is described here in detail. It includes the phasesof problem matching with SA using cubic spline, description of parameters used for SA, curvefitting and the overall algorithm design.

5.1 Problem mapping

This section describes about the SA formulation of the current problem in detail. Our interest isto optimize the values of curve parameters v and w such that the defined curve fits as close to theoriginal contour segments as possible. We use SA for the optimization of these two variables forthe fitted curve. Hence the dimensionality of the solution space is 2. Each state in the SA solutionspace represents a pair of values for v and w. We start with an initial state that is a given pair ofv and w values. A starting temperature is also chosen arbitrarily. This temperature is an inherentinternal parameter of SA and has no significance or mapping on our problem. The algorithmmaintains a record of the best state ever reached throughout the algorithm run. This is the pair of v

and w values that has given the best curve fitting so far. This best solution gets updated wheneverthe algorithm finds a better solution. The algorithm iteratively looks for neighbouring states thatmay or may not be better than the current one. These neighbouring states are v and w values thatare slightly different from the current pair of v and w values. The cooling rate in SA is the factoraffecting the likelihood of selecting a neighbouring pair of v and w values that gives a curve fittingworse than the current pair of v and w values.

Note that we apply SA independently for each segment of a contour that we have identified usingthe corner points. SA is applied sequentially on each of the segments, generating an optimizedfitted curve for each segment. The algorithm is run until the maximum allowed time is reachedor an optimal curve fitting is attained.

5.1.1 Initialization

Once we have the bitmap image of a generic shape, the boundary of the image can be extractedusing the method described in Section 2.1. After the boundary points of the image are found, thenext step is to detect the corner points as explained in Section 2.2. This corner detection technique

Page 9: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1744 M. Sarfraz

assigns a measure of ‘corner strength’ to each of the points on the boundary of the image. Thisstep helps to divide the boundary of the image into n segments. Each of these segments is thenapproximated by interpolating the spline described in Section 3.2. The initial solution of splineparameters (v and w) are randomly selected within the range [−1, 1].

5.1.2 Curve fitting

After an initial approximation for the segment is obtained, better approximations are obtainedthrough SA to reach the optimal solution. We experiment with our system by approximatingeach segment of the boundary using the generalized cubic spline of Section 3.2. This splinemethod is a variation of the well-known Hermite cubic spline. This modified Hermite cubicspline provides greater control on the shape of the curve and is also efficient to compute. Thetangents, in the description of the spline, are computed using least square method. Each boundarysegment is approximated by the spline. The shape parameters v and w in the cubic spline providegreater flexibility over the shape of the curve. These parameters are adjusted using SA to get theoptimal fit.

Once an initial fit for a particular segment is obtained, the parameters of the fitted curve(v’s and w’s) are adjusted to get better fit. Here, we try to minimize the sum-squared error.Using SA, we try to obtain the optimal values of the curve parameters. We choose this techniquebecause it is powerful, yet simple to implement and, as shown in Section 6, performs well for ourpurpose.

5.1.3 Segmentation using intermediate points

For some segments, the best fit obtained through iterative improvement may not be satisfactory.In that case, we subdivide the segment into smaller segments at points where the distance betweenthe boundary and the parametric curve exceeds some predefined threshold, see Figure 5. Suchpoints are termed as intermediate points. A new parametric curve is fitted for each new segment.

5.2 The algorithm

We can summarize all the phases from digitization to optimization discussed in the previoussections. The algorithm of the proposed scheme is contained on various steps. Pseudocode of the

Figure 5. Calculation of intermediate point.

Page 10: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1745

Figure 6. Pseudo-code algorithm with SA.

algorithm is described in Figure 6. A more detailed description, describing the whole system withstep-by-step flow, is shown in the flowchart demonstrated in Figure 7.

5.3 SA parameters used

SA requires an initial guess for the solution. It is this starting-state parameter that affects theperformance of the algorithm. If the starting solution is very near the optimal solution, it ismore likely to find the optimal solution readily than if the starting solution is distant from theoptimal solution. Another important parameter for SA is the temperature. This parameter canbe started arbitrarily at any value since the algorithm decreases it gradually until it reaches itsminimum value. The rate at which the temperature decreases during the running of the algorithmis determined by another parameter: the cooling rate. This is a constant parameter initialized atthe beginning and is used to update the temperature after a certain interval of time.

The maximum time allowed for the algorithm is a static parameter set in the beginning. SinceSA does not terminate unless it exhausts its allotted time, care needs to be given while setting thisparameter. If it is too high, then even if the algorithm reaches an optimal solution, it will not returnunless the maximum time allowed is reached. There is another internal constant that determineshow long it takes before the temperature is updated. This duration is also variable and is adjustedwith the updation variable. Table 1 shows the SA parameter settings that we have used for ourcurve fitting optimization problem.

Page 11: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1746 M. Sarfraz

START

Get DigitizedImage

Extract Contours

from Image

For each extractedcontour loop starts

Detect CornerPoints (CP) of

contour

For each segmentbetween CornerPoints loop starts

ComputeParameterization

for segment

Compute TangentVectors for segmentusing Least Square

Method

Segment loop

Extracted contoursloop

END

Start of SA to getOptimized values for vand w for fitted curve

on given segment

InitializationSelect a starting state

Set Cooling RateSet Starting Temperature

While MaxAllowed Time Not

Reached

While ParameterUpdation Time Not

Reached

No

No

No

Yes

Yes

ParameterUpdation loop

UpdateTemperature

Max Allowed Timeloop

SA Algorithm ends

Select NewNeighbor State

Compute Fitness Value

and fitted curve)actual contour segment

distance betweenof New State (total

New Fitness valuebetter than Current

Current State =New State

Best State = New State

Probability to SelectWorse State

Yes

Current State =New State

Fitness Value

New Fitness valuebetter than BestFitness Value

Figure 7. Flowchart of the system with SA.

Page 12: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1747

Table 1. Parameter settings for SA.

SA parameters Values

Range of input parameters v and w [−1, 1]Fitness function optimization target 0 (function minimization)Dimension of problem (number of inputs to SA) 2Weight given to global search vs. local search 20Maximum number of iterations (epochs) 200Stopping relative error (if distance from optima is less than

this, the algorithm terminates)1 × 10−4

Initial set of solution points Corner points and mid-points of solution spaceNumber of steps in local search 50

6. Demonstration

The algorithm in Section 5 has been implemented practically, and the proposed curve scheme hasbeen implemented with and without intermediate point incorporation. Use of SA has providedpleasing and efficient results. Experiments are done using MATLAB 7.1 in a Dell Inspiron machinewith dual-core processor (1.66 GHz) and 1 GB RAM. We evaluate the performance of our systemby fitting parametric curves to different binary images.

Figure 8 shows the implementation results of the algorithm with SA. Figure 8(a)–(d) are,respectively, the original image of an Arabic language word ‘Ilm’, its outline, outline togetherwith corner points detected, and the fitted outline together with corner points and intermediatepoints.

Figures 9(a)–(d) demonstrate, respectively, 1st, 5th, 10th and last (62th) iterations of thealgorithm using SA without inserting any intermediate point. Since the number of iterationsmay not be the same for each segment, the number of iterations for the whole curve mentionedhere actually represents the average number of iterations per segment. This experiment is donewithout inserting any intermediate point in any of the curve segment. One can notice that aftersome iterations, although an approximation curve has been achieved, still it is required to havesome further improvements. Figure 8(d) demonstrates the improvement in the output. This is doneby inserting some appropriate intermediate points in the desired curve segments. One can noticethat after some iterations, a pleasing approximate curve has been achieved. However, an extra costof having more intermediate points has been paid together with the cost of more iterations. Thiscost, the author believes, is bearable as the computation time consumed is not very significant ascompared with the time paid to achieve not a good approximation in Figure 9. Moreover, accuracyachieved in Figure 8 is much higher and visually acceptable.

Some more experiments are done on different images. An image of a plane is shown inFigure 10(a), its outline is detected in Figure 10(b) and the corner points are shown in Figure 10(c).

Figure 8. Preprocessing steps: (a) original image, (b) outline of the image, (c) corner points achieved and (d) fittedoutline of the image.

Page 13: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1748 M. Sarfraz

Figure 9. Demonstration of spline fitting at different iterations (average per segment) using SA without intermediatepoint: (a) 1st iteration, (b) 5th iteration, (c) 10th iteration and (d) 62th (final) iteration.

Figure 10. Preprocessing steps for curve fitting: (a) image of a plane, (b) extracted outline and (c) initial corner points.

Figure 11. Cubic curve fitting (a) without intermediate points and (b) with intermediate points.

Figures 11(a) and (b) demonstrate the fitted curves to the outline of Figure 10(b) corresponding tothe scheme without and with insertion points, respectively. It can be noticed that the fitted curvein Figure 11(a) has a good approximation without inserting extra points. However, inserting extrapoints has highly refined the approximation in Figure 11(b).

Another experiment is made on an image of a fork in Figure 12(a). Its outline is detected inFigure 12(b) and the corner points are shown in Figure 12(c). Figures 13(a) and 13(b) demonstratethe fitted curves to the outline of Figure 12(b) corresponding to the scheme without and withinsertion points, respectively. It can be noticed that the fitted curve in Figure 13(a) has a goodapproximation, without inserting extra points, except at two segments. However, inserting extrapoints has highly refined the approximation everywhere in Figure 13(b).

Page 14: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1749

Figure 12. Preprocessing steps for curve fitting: (a) image of a plane, (b) extracted outline and (c) initial corner points.

Figure 13. Cubic curve fitting (a) without intermediate points and (b) with intermediate points.

Table 2. Names and contour details of images.

Image Name Number of contours Number of contour points

Ilm.bmp 1 [1641]

Plane.bmp 3 [1106 + 61 + 83]

Fork.bmp 1 [693]

Table 3. Comparison of objective function values for cubic interpolation approaches.

Objective function value for cubic interpolation

Image Without intermediate points With intermediate points

Ilm.bmp 13479.5468 1229.8292Plane.bmp 2911.4841 1205.1647Fork.bmp 5585.6414 439.8825

Page 15: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

1750 M. Sarfraz

Table 4. Comparison of number of initial corner points, intermediate points and total time taken (in seconds) for cubicinterpolation approaches.

Total time taken for cubic interpolationNumber of initial Number of intermediate

Image corner points points in cubic interpolation Without intermediate points With intermediate points

Ilm.bmp 18 33 308.479 749.511Plane.bmp 31 13 179.786 286.033Fork.bmp 10 22 135.453 486.722

Table 5. Comparison of number of function calls taken by SA cubic interpolation approach with and withoutintermediate points.

Number of function calls taken by SA

Cubic interpolation without Cubic interpolation withImage intermediate points intermediate points

Ilm.bmp 27600 55305Plane.bmp 38211 53108Fork.bmp 16106 45212

Tables 2–5 summarize the experimental results for different bitmap images. These resultshighlight various information including contour details of images (Table 2), comparison ofobjective function values (Table 3), intermediate points (Table 4), and number of iterations(Table 5).

7. Conclusion and future work

A global optimization technique, based on SA, is proposed for the outline capture of planarimages. The proposed technique uses the SA to optimize a cubic spline to the digital outline ofplanar images. By starting a search from certain good points (initially detected corner points),an improved convergence result is obtained. The overall technique has various phases includingextracting outlines of images, detecting corner points from the detected outline, curve fitting andaddition of extra knot points if needed. The idea of SA has been used to optimize the shapeparameters in the description of the generalized cubic spline introduced. The spline method ulti-mately produces optimal results for the approximate vectorization of the digital contour obtainedfrom the generic shapes. It provides an optimal fit with an efficient computation cost as far ascurve fitting is concerned. The proposed algorithm is fully automatic and requires no human inter-vention. Implementation details are sufficiently discussed using both with and without insertionof intermediate points. The proposed technique has been supported with numerical and pictorialresults demonstrated. In future, the author is intending to look at an alternative global optimizationtechnique [9] based on multilevel coordinate search. This might investigate some other scenariosfor the improvement in the proposed technique.

Acknowledgement

This work was supported by Kuwait University, Research Grant No. [WI 01/08].

Page 16: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

International Journal of Computer Mathematics 1751

References

[1] J.C. Carr, R.K. Beatson, J.B. Cherrie, T.J. Mitchell, W.R. Fright, B.C. McCallum, and T.R. Evans, Reconstructionand representation of 3D objects with radial basis functions, In Proceedings of the 28th Annual Conference onComputer Graphics and Interactive Techniques, ACM New York, NY, USA, 2001, pp. 67–76.

[2] R. Carr, Simulated annealing. From MathWorld: A Wolfram Web Resource created by Eric W. Weisstein, softwareavailable at http://mathworld.wolfram.com/SimulatedAnnealing.html.

[3] D. Chetverikov and Z. Szabo, A simple and efficient algorithm for detection of high curvature points in planarcurves, in Proceedings of the 23rd Workshop of the Austrian Pattern Recognition Group, Steyr, 1999, pp. 175–184.

[4] H. Freeman and L.S. Davis, A corner finding algorithm for chain-coded curves, IEEE Trans. Computers 26 (1977),pp. 297–303.

[5] A.A. Goshtasby, Grouping and parameterizing irregularly spaced points for curve fitting, ACM Trans. Graphics19(3) (2000), pp. 185–203.

[6] J.H. Horng, An adaptive smoothing approach for fitting digital planar curves with line segments and circular arcs,Pattern Recognition Lett. 24(1–3) (2003), pp. 565–577.

[7] Z.J. Hou and G.W. Wei, A new approach to edge detection, Pattern Recognition 35(7) (2002), pp. 1559–1570.[8] W.-C. Hu, Multiprimitive segmentation based on meaningful breakpoints for fitting digital planar curves with line

segments and conic arcs, Image Vision Comp. 23(9) (2005), pp. 783–789.[9] W. Huyer and A. Neumaier, Global optimization by multilevel coordinate search, J. Global Optim. 14 (1999),

pp. 331–355.[10] B. Jüttler andA. Felis, A least square fitting of algebraic spline surfaces,Adv. Comput. Math. 17 (2002), pp. 135–152.[11] H. Kano, H. Nakata, and C.F. Martin, Optimal curve fitting and smoothing using normalized uniform B-splines:

A tool for studying complex systems, Appl. Math. Comp. 169(1) (2005), pp. 96–128.[12] S. Kirkpatrick, C.D. Gelatt Jr., and M.P. Vecchi, Optimization by simulated annealing, Science 220(4598) (1983),

pp. 671–680.[13] G. Lavoue, F. Dupont, and A. Baskurt, A new subdivision based approach for piecewise smooth approximation of

3D polygonal curves, Pattern Recognition 38(8) (2005), pp. 1139–1151.[14] M. Marji and P. Siv, A new algorithm for dominant points detection and polygonization of digital curves, Pattern

Recognition 36(10) (2003), pp. 2239–2251.[15] B.S. Morse, T.S. Yoo, D.T. Chen, P. Rheingans, and K.R. Subramanian, Interpolating implicit surfaces from

scattered surface data using compactly supported radial basis functions, in SMI 01 Proceedings of the InternationalConference on Shape Modeling and Applications, 8998, Washington, DC, IEEE Computer Society, 2001.

[16] P. Reche, C. Urdiales, A. Bandera, C. Trazegnies, and F. Sandoval, Corner detection by means of contour localvectors, Electron. Lett. 38(14) (2002), pp. 699–701.

[17] N. Richard and T. Gilbert, Extraction of dominant points by estimation of the contour fluctuations, Pattern Recognition35 (2002), pp. 1447–1462.

[18] M. Sarfraz, Some algorithms for curve design and automatic outline capturing of images, Int. J. Image and Graphics4(2) (2004), pp. 301–324.

[19] M. Sarfraz, Computer-aided reverse engineering using simulated evolution on NURBS, Int. J. Virtual Phys.Prototyping 1(4) (2006), pp. 243–257.

[20] M. Sarfraz, Designing objects with a spline, Int. J. Comp. Math., preprint (2008), DOI: 10.1080/00207160802196009.[21] M. Sarfraz and M.A. Khan, An automatic algorithm for approximating boundary of bitmap characters, Future

Generation Comp. Syst. 20(8) (2004), pp. 1327–1336.[22] M. Sarfraz and A. Rasheed, A randomized knot insertion algorithm for outline capture of planar images using cubic

spline, The Proceedings of the 22th ACM Symposium on Applied Computing (ACM SAC-07), Seoul, Korea ACMPress, (2007), pp. 71–75.

[23] M. Sarfraz, M. Riyazuddin, and M.H. Baig, Capturing planar shapes by approximating their outlines, Int. J. Comput.Appl. Math. 189(1–2) (2006), pp. 494–512.

[24] B. Sarkar, L.K. Singh, and D. Sarkar, Approximation of digital curves with line segments and circular arcs usinggenetic algorithms, Pattern Recognition Lett. 24(15) (2003), pp. 2585–2595.

[25] Simulated annealing: annealing applet, software available at http://www.heatonresearch.com/articles/64/page1.html.

[26] M. Sonka, V. Hlavac, and R.D. Boyle, Image Processing, Analysis, and Machine Vision, third edition. Brooks Cole,Pacific Grove, CA, 2001.

[27] H. Yang, W. Wang, and J. Sun, Control point adjustment for B-spline curve approximation, Comput. Aided Des.36(7) (2004), pp. 639–652.

[28] X. Yang, Curve fitting and fairing using conic spines, Comput. Aided Des. 36(5) (2004), pp. 461–472.[29] X.N. Yang and G.Z. Wang, Planar point set fairing and fitting by arc splines, Comput. Aided Des. 33(1) (2001),

pp. 35–43.[30] Z. Yang, J. Deng, and F. Chen, Fitting unorganized point clouds with active implicit B-spline curves, Vis. Comput.

21(8–10) (2005), pp. 831–839.

Page 17: Vectorizing outlines of generic shapes by cubic spline using simulated annealing

Copyright of International Journal of Computer Mathematics is the property of Taylor & Francis Ltd and its

content may not be copied or emailed to multiple sites or posted to a listserv without the copyright holder's

express written permission. However, users may print, download, or email articles for individual use.