Class LinearContourLabelChang2004

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

public class LinearContourLabelChang2004
extends Object

Finds objects in a binary image by tracing their contours. The output is labeled binary image, set of external and internal contours for each object/blob. Blobs can be defined using a 4 or 8 connect rule. The algorithm works by processing the image in a single pass. When a new object is encountered its contour is traced. Then the inner pixels are labeled. If an internal contour is found it will also be traced. See [1] for all the details. The original algorithm has been modified to use different connectivity rules.

Output: Background pixels (0 in input image) are assigned a value of 0, Each blob is then assigned a unique ID starting from 1 up to the number of blobs.

The maximum contour size says how many elements are allowed in a contour. if that number is exceeded by the external contour the external contour will be zeroed. Internal contours that exceed it will be discarded. Note that the all external and internal contours will still be traversed they will just not be recorded if too large.

Internally, the input binary image is copied into another image which will have a 1 pixel border of all zeros around it. This ensures that boundary checks will not need to be done, speeding up the algorithm by about 25%.

[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

  • Constructor Details

    • LinearContourLabelChang2004

      public LinearContourLabelChang2004​(ConnectRule rule)
      Configures the algorithm.
      Parameters:
      rule - Connectivity rule. 4 or 8
  • Method Details

    • process

      public void process​(GrayU8 binary, GrayS32 labeled)
      Processes the binary image to find the contour of and label blobs.
      Parameters:
      binary - Input binary image. Not modified.
      labeled - Output. Labeled image. Modified.
    • getContours

      public DogArray<ContourPacked> getContours()
    • setConnectRule

      public void setConnectRule​(ConnectRule rule)
    • getConnectRule

      public ConnectRule getConnectRule()