findContours: Find Contours in a Binary Image

View source: R/shape.R

findContoursR Documentation

Find Contours in a Binary Image

Description

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

Usage

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

Arguments

image

An 8-bit (8U) single-channel (GRAY) 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 matrices:

  • "contours": a matrix 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 matrix 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.

Author(s)

Simon Garnier, garnier@njit.edu

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

Image

Examples

dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
dots_gray <- changeColorSpace(dots, "GRAY")
dots_bin <- dots_gray < 200
contours <- findContours(dots_bin)


swarm-lab/Rvision documentation built on Feb. 7, 2024, 4:59 a.m.