approxPolyDP | R Documentation |
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.
approxPolyDP(curve, epsilon, closed = TRUE)
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). |
A matrix with two columns:
the x coordinates of the approximated curve.
the y coordinates of the approximated curve.
Simon Garnier, garnier@njit.edu
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
findContours
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.