Adaptive Shape Contour Tracing Algorithm by E mad Att alla, Ph. D. ABSTRACT In this paper we are going to present a new shape contour tracing algorithm called! SSAdaptive Contour Tracing Algorithm!" . The algorithm can trace open and closed discontinuous digital shapes and return an ordered set of boundary points that represent the contour of the shape.

Unlike other algorithms that return boundary points that are part of the traced shape, our algorithm returns background points that are adjacent to the shape! |s contour. Furthermore, the algorithm is not hindered by shapes that are noisy and ill-defined as it can adapt to interruptions in the shape! |s contour using a pre-set tolerance and is able to scan multiple neighbors of a given point. The algorithm has a low complexity and no restrictions on the type or size of the traced shape. The extracted ordered set of boundary points represents the contour of a given shape and is important for curvature-based shape descriptors. Categories and Subject Descriptors I. 4.

6 [Image Processing and Computer Vision]: Segmentation! V Edge and feature detection, Pixel classification General Terms Algorithms. Keywords Image Processing; Contour Tracing; Shape Boundary Extraction. 1. INTRODUCTION Contour tracing is an important process in boundary-based shape matching. All shapes are represented by a pattern of pixels and the contour pixels are usually a small subset of that pattern. Curvature-based shape matching methods rely on the contour pixels to describe the irregularities in shapes and a reliable contour-tracing algorithm is needed to extract the boundary of shapes.

If the shape has holes then another hole search algorithm need to be applied to extract the hole pattern and such an algorithm is not part of this article. We developed a sequential contour-tracing algorithm denoted the! SSAdaptive Contour Tracing Algorithm!" . The algorithm computes the surrounding contour of any shape and adapts to all types of closed curve representations whether they are filled or partially filled digital shapes. Any pixel, 1-pixel wide lines, and full shapes could be traced and represented by closed curves.

The algorithm also accounts for discontinuities in the shape contour and can reach nearby pixels. The contour trace starts from the top left point or pixel closest to the shape and proceeds clockwise following the surrounding of the contour of the shape rather than the contour itself. The path around the contour is traced in a look-forward sweep pattern to find the next surrounding point that is closest to the contour. The path is then closed when the start point is found. 2. ADAPTIVE CONTOUR TRACING Input Data: A square tessellation, Q, of Q-width x Q-height containing cells that belong to the shape and cells that belong to the background of the shape.

A Tessellation is a group of cells (pixels in images) that has the same shape and size. Definitions: 1- Each cell is represented by an x-y coordinate point p = (x, y) 2- The terms! SS cell!" , ! SS point!" and! SS pixel!" all refer to the same definition of a cell. 3- Define 8-neighbor (cell, direction) as Moore! |s neighborhood which is a common concept that defines the 8-neighboring cells of any cell as shown in 4- Define i-order neighbor of any cell i-order (cell, direction) as the set of (i 8) cells, where i > 0, that are i-1 cells away from that cell. Moore! |s Neighbor corresponds to our 1-order notation. The 2-order neighbor contains 16 cells and 3-order neighbor contains 24 cells as shown in Figure 2. 5- Define 4 orientations to read cells around any cell p: (LR-Direction, RL-Direction, DU-Direction and UD-Direction) as shown in Figure 3.

6- The top-left cell of Q has (x, y) = (1, 1) and the x-axis increases from left to right and the y-axis increases from top to bottom. 7- Let s denotes any shape cell, p denotes any background cell, c and d denote any cell, C and D are the set of cells of i-order around cells c and d respectively. 8- When disregarding 1-pixel shapes, Define a stranded point s as a cell where all 8-neighbor or 1-order cells = p. 9- Define neighborhood tolerance factor T as the maximum i-order where the trace algorithm should keep looking for a contour boundary. Output Data: An ordered sequence P (p 1, p 2, ! K, pn) of n contour boundary points.

The Algorithm: - Set P to be empty. - From top to bottom and left to right scan the cells of Q until the leftmost shape pixel s 1 with (x 1, y 1) coordinate is found as shown in figure 4. - Insert p 1 = (x 1-1, y 1), left background cell next to s 1, in P. - Set start point = p 1, previous point = p 1, current direction = DU, i-order = 1- Set p 2 = getNextPoint (1, p 1, DU) and Insert p 2 in P.

- Set n = 3- While true do (Comment: Scan all i-orders up to maximum tolerance T) For i = 1 to T Set pn = get Next (i, pn-1, pn-2) If pn = p 1 then exit while loop If pn is not empty Then Insert pn in P Set n = n+1 Exit For Loop End If Next i End While Function get Next Input Parameters: i-order i, current point, previouspointOutput Parameters: nextpointBegin (Comment: the direction of movement is switched between the four directions depending on the increase and decrease in the x and y coordinate values of the previous and current points) If current point. x > previous point. x Thennextpoint = getNextPoint (i, current point, LR-direction) Else If current point. x < previous point. x Thennextpoint = getNextPoint (i, current point, RL-direction) Else If current point. x = previous point.

x Then If current point. y > previous point. y Thennextpoint = getNextPoint (i, current point, UD-direction) Else If current point. y < previous point.

y Thennextpoint = getNextPoint (i, current point, DU-direction) End If End If End Function getNextFunction getNextPointInput Parameters: i-order i, current point, currentdirectionOutput Parameters: next point Set next point = emptyBeginSet C = i-order (current point, current direction) For n = 1 to (i 8) where cn "! C (Comment: if cn is a background cell then in order to use it as a boundary point it must have an i-order background cell and the later must have an 8-neighbor shape cell that is not stranded - if stranded checking is enabled) If (cn = p) Then Set D = 8-neighbor (cn, current direction) For m = 1 to 8 where dm "! DIf (dm = s) and (s is not stranded) and (cn not traced before) Then Set next point = cn Set cn to be traced Exit For End If Next m End If Next n End Function getNextPoint 3. COMPARISONS WITH OTHERS There were many contour tracing algorithms proposed in the literature such as the Square Tracing Algorithm [1][2], Moore-Neighbor Tracing [3], Radial Sweep [4] and Pavlidis Algorithm [5]. All of the available contour tracing algorithms return contour points that belong to the shape rather than the surroundings of the shape. They are also concerned with continues contours where all contour pixels need to have a an 8-neighbor shape pixel.

Our algorithm does not look for a shape contour cell in the 8-neighbor cells of the current cell like other algorithms but rather it looks in the 8-neighbor cells of each of the i-order cells of the current cell in the current direction (Figure 5) and tries to find an adjacent shape contour cell to a potential background cell. In other words, we look in the 1-order and 2-order cells of the current cell at the same time. This concept is what makes it immune to discontinuities in the shape! |s contour as it can jump over openings in the contour. The current pixel does not belong to the shape! |s contour but rather to its surroundings. The selected direction depends on the x-y coordinates of the current and previous background cells traced as defined in get Next function. The start up direction of the start point is DU-direction as there is no prior point.

Our algorithm can handle discontinuous contours by adapting to a specified neighborhood tolerance as shown in the traced shape of Figure 6. The neighborhood tolerance specifies how far to look for a contour pixel from the current position. The algorithm is not restricted to the 8-neighbor pixels of a pixel but rather it can look forward to other neighbors as the 16-neighbor and 24-neighbor pixels. This algorithm has the power to trace shapes such as a thin line that is 1-pixel wide or shapes that contain only 1 pixel or 2 pixels as shown in Figure 7. To trace a 1 pixel shape, the check for stranded point has to be disabled.

Stranded points are pixels in the background that are cut off from the shape pattern... Tracing 1-pixel is possible due to tracing the surroundings of the shape rather that the contour of the shape. Figure 8 shows a variety of shapes traced with our algorithm. The algorithm is robust and not calculation intensive. The time complexity of the algorithm is O (n) where n is the number of shape contour pixels. 4.

SUMMARY AND CONCLUSION The adaptive contour tracing algorithm presented the new concept of tracing the surrounding of the shape rather than the contour itself. This concept has the advantage of tracing any closed or open shape even if it was a single pixel. The algorithm can also trace distorted and disconnected boundaries since it is not using the surrounding 8-neighbors of pixels but rather the 8-neighbors of each of the 8-neighbors of the current pixel. This concept needs to be enhanced to resolve these 2 issues: 1) The failure to differentiate between open gaps and actual contour convex as shown in figure 9 as the 1 pixel gap in the contour of the camel was not a discontinuity but the algorithm did not have any logic to differentiate between an opening in the contour and following the contour. One solution to this might be to use a contour extraction algorithm like the Canny Algorithm and the addition of logic to insure that all the contour pixels returned by the Canny Algorithm has been traced. 2) The failure to trace very small shapes of around 10 pixels as the returned trace could be coarse and may not reflect the actual shape as shown in figure 10.

5. REFERENCES[1] A. Rosenfeld, ! SSDigital Topology, !" American Mathematical Monthly, pp. 621-630, vol. 86, 1979. [2] A.

Rosenfeld, R. A. Melter, ! SSDigital Geometry, !" The Mathematical Intelligencer, pp 69-72, vol. 11, No. 3, 1989.

[3] R. C. Gonzalez and R. E.

Woods. Digital Image Processing, 2 nd ed. , Prentice Hall, Upper Saddle River, NJ. 2002.

[4] F. P. Preparata and M. I.

Shams. Computational Geometry: An Introduction. Springer-Verlag, New York, NY, 1985. [5] T.

Pavlidis. Algorithms for graphics and image processing. Computer Science Press, Rockville, MD, 1982.