findContours
retrieves contours from a binary image using
the algorithm by Suzuki & Be (1985).
findContours(image, mode = "external", method = "simple", offset = c(0, 0))
An 8-bit (8U) single-channel (GRAY) Image
object.
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 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).
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.
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.
Suzuki, S., and Be, K. (1985). Topological structural analysis of digitized binary images by border following. Computer Vision, Graphics, and Image Processing 30, 32<U+2013>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<U+2013>872. doi:10.1109/34.31447.
# NOT RUN {
dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
dots_gray <- changeColorSpace(dots, "GRAY")
dots_bin <- dots_gray < 200
contours <- findContours(dots_bin)
# }
Run the code above in your browser using DataLab