Boundary Tracing
Get Boundary Tracing essential facts below. View Videos or join the Boundary Tracing discussion. Add Boundary Tracing to your topic list for future reference or share this resource on social media.
Boundary Tracing

Boundary tracing, also known as contour tracing, of a binary digital region can be thought of as a segmentation technique that identifies the boundary pixels of the digital region. Boundary tracing is an important first step in the analysis of that region.


Algorithms used for boundary tracing:[1]

  • Square tracing algorithm[2]
  • Moore-neighbor tracing algorithm
  • Radial sweep [3]
  • Theo Pavlidis' algorithm [4]
  • A generic approach using vector algebra for tracing of a boundary can be found at.[5]
  • An extension of boundary tracing for segmentation of traced boundary into open and closed sub-section is described at.[6]

Square tracing algorithm

The square tracing algorithm is simple, yet effective. Its behavior is completely based on whether one is on a black, or a white cell (assuming white cells are part of the shape). First, scan from the upper left to right and row by row. Upon entering your first white cell, the core of the algorithm starts. It consists mainly of two rules:

  • If you are in a white cell, go left.
  • If you are in a black cell, go right.

Keep in mind that it matters how you entered the current cell, so that left and right can be defined.

public void GetBoundary(byte[,] image)
    for (int j = 0; j < image.GetLength(1); j++)
        for (int i = 0; int i < image.GetLength(0); i++)
            if (image[i, j] == 255)               // Found first white pixel
                SquareTrace(new Point(i, j));

public void SquareTrace(Point start)
    HashSet<Point> boundaryPoints = new HashSet<Point>;  // Use a HashSet to prevent double occurrences
    // We found at least one pixel

    // The first pixel you encounter is a white one by definition, so we go left. 
    // Our initial direction was going from left to right, hence (1, 0)
    Point nextStep = GoLeft(new Point(1, 0));               
    Point next = start + nextStep;
    while (next != start)
        // We found a black cell, so we go right and don't add this cell to our HashSet
        if (image[next.x, next.y] == 0)
            next = next - nextStep
            nextStep = GoRight(nextStep);
            next = next + nextStep;
        // Alternatively we found a white cell, we do add this to our HashSet
            nextStep = GoLeft(nextStep);
            next = next + nextStep;

private point GoLeft(Point p) => new Point(p.y, -p.x);
private point GoRight(Point p) => new Point(-p.y, p.x);

See also


  1. ^ Contour Tracing Algorithms
  2. ^ Abeer George Ghuneim: square tracing algorithm
  3. ^ Abeer George Ghuneim: The Radial Sweep algorithm
  4. ^ Abeer George Ghuneim: Theo Pavlidis' Algorithm
  5. ^ Vector Algebra Based Tracing of External and Internal Boundary of an Object in Binary Images, Journal of Advances in Engineering Science Volume 3 Issue 1, January-June 2010, PP 57-70 [1]
  6. ^ Graph theory based segmentation of traced boundary into open and closed sub-sections, Computer Vision and Image Understanding, Volume 115, Issue 11, November 2011, pages 1552-1558 [2]

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Music Scenes