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.
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
Simon Garnier, garnier@njit.edu
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)
#> start_index end_index farthest_pt_index fixpt_depth
#> [1,] 1 2 2 210
#> [2,] 3 4 4 186
#> [3,] 5 6 6 162
#> [4,] 7 8 8 114
#> [5,] 17 18 18 142
#> [6,] 20 21 21 142
#> [7,] 24 25 25 114
#> [8,] 28 29 29 190
#> [9,] 32 33 33 186
#> [10,] 37 38 38 186
#> [11,] 41 42 42 162
#> [12,] 43 44 44 114
#> [13,] 53 54 54 142
#> [14,] 58 59 59 142
#> [15,] 62 63 63 114
#> [16,] 67 68 68 114
#> [17,] 69 70 70 142
#> [18,] 72 73 73 142
#> [19,] 76 77 77 114
#> [20,] 80 81 81 162
#> [21,] 86 87 87 201
#> [22,] 89 90 90 201
#> [23,] 91 92 92 162
#> [24,] 97 98 98 114
#> [25,] 105 106 106 142
#> [26,] 107 108 108 154
#> [27,] 110 111 111 142
#> [28,] 114 115 115 114
#> [29,] 122 123 123 190
#> [30,] 126 127 127 186
#> [31,] 128 129 129 210