I am trying to implement a siplification algorithm. The main 2 algorithms I found are Ramer-Douglas-Peucker: https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm and Visvalingam-Whyatt: https://bost.ocks.org/mike/simplify/ Currently I am running a few simulations of them on matlab in order to determine which answers my needs better.
The main goal for the algorithm is to simlipfy polygons in a map. My Input is a polygon\polyline and a threshold for mistake- epsilon.
I need the simlified polygon to be as close as possible to the original, and I do not have a requirment for number of points to keep.
I am having difficulties in comparing the two algorithms because: epsilon for R-D-P is a distance while epsilon for V-W is an area. I need help understanding how to compare between the two algorithms. which can give me less points to keep within the threshold?
DP method will give you better perceptible fit with lesser number of points - as its control parameter i.e the distance tolerance is captured by your requirement 'as close as possible'.
Having said that, the scale of the overall polygon or point-cloud relative to the pixel dimensions will have a bigger impact for smaller images. The exercise below can give you a 'feel' for how the two algorithms perform.
Here are some comparisons I ran between Visvalingam-Whyatt and Ramer-Douglas-Peucker for a few contours contained in what is around 100x100 bitmap originally. The images are screenshots of a ~ 10x zoom on the contours.
(you might want to download the images to appreciate the differences in performance)
Visvalingam-Whyatt method results : courtesy Zach's implementation on github ported to opencv data types.
VSV simplification - with 0.55(white), 0.4(red), 0.25(magenta), 0.15(cyan) percentage tolerances
VSV - point reductions t : % tolerance . this directly determines n = t*orig/100. n is the final number of points
DP method results using openCV approxPolyDP
Douglas-Peucker - point reductions t : pixel distance tolerance => no direct correlation to n - the final number of points
Summary :
For my application, I prefer the control offered by VWV in this implementation over the possible efficiency of DP method.
But overall I feel openCVs's DP implementation gives a smoother perception.
Though my conclusions of VSV performance are based on Zach's implementation alone, I doubt if other implementations will give characteristically different polygon subsets.
[UPDATE1] Here is the comparison for a worst case scenario. DP is visually more acceptable.