Class LinearExternalContours

java.lang.Object
boofcv.alg.filter.binary.LinearExternalContours

public class LinearExternalContours extends Object
Finds the external contours of binary blobs in linear time. No label image is required. Designed to quickly move through regions with repeat values of 0 and 1. Input image is modified. The outside border is set to zero and the value of contour pixels is set to -1 or -2 to indicate that it has been processed. This algorithm is highly specialized but follows a similar pattern to other finding/tracing algorithms from [1] and [2]. Algorithm:
  1. Fill in image border with zeros
  2. Start at pixel x=1,y=1
  3. Begin Row: Starting at (x,y) scan for a value of not zero. Let this point be (x,y)
  4. Trace contour. This contour must be an external contour and is saved.
  5. Resume scanning the row starting at (x+1,y) for a pixel with a value of zero. This pixel will now be (x,y)
  6. If the pixel (x-1,y) has a value of 1 trace the inner contour. Otherwise move to next step.
  7. Iterate from "Begin Row" until the end of the row has been reached
  8. Move to the next row starting at point (1,y+1)
Look at the code for all the details. There are a couple of important points which are glossed over in the description above. To get the external contours after processing call getExternalContours().

[1] Fu Chang and Chun-jen Chen and Chi-jen Lu, "A linear-time component-labeling algorithm using contour tracing technique" Computer Vision and Image Understanding, 2004
[2] Rosenfeld, Azriel. "Digital topology." American Mathematical Monthly (1979): 621-630.

  • Constructor Details

    • LinearExternalContours

      public LinearExternalContours(ConnectRule rule)
  • Method Details

    • process

      public void process(GrayU8 binary, int adjustX, int adjustY)
      Detects contours inside the binary image.
      Parameters:
      binary - Binary image. Will be modified. See class description
      adjustX - adjustment applied to coordinate in binary image for contour. 0 or 1 is typical
      adjustY - adjustment applied to coordinate in binary image for contour. 0 or 1 is typical
    • getConnectRule

      public ConnectRule getConnectRule()
    • setConnectRule

      public void setConnectRule(ConnectRule rule)
    • getExternalContours

      public PackedSetsPoint2D_I32 getExternalContours()