convexityDefects: Find the Convexity Defects of a Polygon

View source: R/shape.R

convexityDefectsR Documentation

Find the Convexity Defects of a Polygon

Description

convexityDefects finds the convexity defects of a polygon, that is the area that do not belong to an object but are located inside of its convex hull.

Usage

convexityDefects(x)

Arguments

x

A Nx2 matrix of the X-Y coordinates of a polygon (e.g., a contour produced by findContours)

Value

A matrix with 4 columns:

  • "start_index": index of the first point of the contour belonging to a convexity defect.

  • "end_index": index of the last point of the contour belonging to a convexity defect.

  • "farthest_pt_index": index of the point of the contour belonging to a convexity defect and that is the farthest away from the convex hull.

  • "fixpt_depth": distance between the farthest contour point and the convex hull.

Author(s)

Simon Garnier, garnier@njit.edu

See Also

findContours, convexHull

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)
contour0 <- contours$contours[contours$contours[, 1] == 0, 2:3]
convexityDefects(contour0)


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