approxPolyDP
approximates a curve or a polygon with
another curve/polygon with less vertices so that the distance between them
is less or equal to the specified precision. It uses the Douglas-Peucker
algorithm.
Value
A matrix with two columns:
- "x":
the x coordinates of the approximated curve.
- "y":
the y coordinates of the approximated curve.
References
Douglas, D. H., & Peucker, T. K. (1973). ALGORITHMS FOR THE REDUCTION OF THE NUMBER OF POINTS REQUIRED TO REPRESENT A DIGITIZED LINE OR ITS CARICATURE. Cartographica: The International Journal for Geographic Information and Geovisualization, 10(2), 112–122. doi:10.3138/FM57-6770-U75U-7727
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)
ix <- contours$contours[, 1] == 0
approxPolyDP(contours$contours[ix, 2:3], 10)
#> x y
#> [1,] 532 97
#> [2,] 510 63
#> [3,] 518 24
#> [4,] 543 1
#> [5,] 593 2
#> [6,] 615 33
#> [7,] 608 77
#> [8,] 575 103