Skip to contents

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.

Usage

approxPolyDP(curve, epsilon, closed = TRUE)

Arguments

curve

An m x 2 matrix of 2D coordinates.

epsilon

A numeric specifying the approximation accuracy. This is the maximum distance between the original curve and its approximation.

closed

A logical indicating whether the curve is closed (perimeter) or not (default: TRUE).

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

See also

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