findContours retrieves contours from a binary image using the algorithm by Suzuki & Be (1985).

findContours(image, mode = "external", method = "simple",
  offset = c(0, 0))

Arguments

image

An 8-bit (8U) single-channel Image object.

mode

Mode of the contour retrieval algorithm. It can take the following values:

  • 'external': retrieves only the extreme outer contours (the default).

  • 'list': retrieves all of the contours without establishing any hierarchical relationships.

  • 'ccomp': retrieves all of the contours and organizes them into a two-level hierarchy. At the top level, there are external boundaries of the components. At the second level, there are boundaries of the holes. If there is another contour inside a hole of a connected component, it is still put at the top level.

  • 'tree': retrieves all of the contours and reconstructs a full hierarchy of nested contours.

method

Method for approximating the contours. It can take the following values:

  • 'none': stores absolutely all the contour points.

  • 'simple': compresses horizontal, vertical, and diagonal segments and leaves only their end points (the default).

  • 'l1': applies one of the flavors of the Teh-Chin chain approximation algorithm (Teh & Chin, 1989).

  • 'kcos': applies one of the flavors of the Teh-Chin chain approximation algorithm (Teh & Chin, 1989).

offset

A 2-element vector representing the offset by which every contour point should be shifted (default: c(0, 0)). This is useful if the contours are extracted from the image ROI but then should be analyzed in the whole image context.

Value

A list of two data frames:

  • "contours": a data frame with 3 columns:

    • "id": the contour identity (indicates the set of points belonging to the same contour).

    • "x": the x coordinates of the contour points.

    • "y": the y coordinates of the contour points.

  • "hierarchy": a data frame with 5 columns:

    • "id": the contour identity.

    • "after": the identity of the next contour at the same hierarchical level.

    • "before": the identity of the previous contour at the same hierarchical level.

    • "child": the identity of the first child contour.

    • "parent": the identity of the parent contour.

References

Suzuki, S., and Be, K. (1985). Topological structural analysis of digitized binary images by border following. Computer Vision, Graphics, and Image Processing 30, 32–46. doi:10.1016/0734-189X(85)90016-7.

Teh, C.-H., and Chin, R. T. (1989). On the detection of dominant points on digital curves. IEEE Trans. Pattern Anal. Mach. Intell. 11, 859–872. doi:10.1109/34.31447.

See also

Author

Simon Garnier, garnier@njit.edu

Examples

# TODO