dpsimplify uses the recursive Douglas-Peucker line simplification algorithm to reduce the number of vertices in a polyline according to a specified tolerance. The algorithm is also know as Iterative Endpoint Fit algorithm. dpsimplify can handle polylines and polygones in 2d and higher dimensions.
The submission now contains another m-file (dpsimplify_octave.m) that has been slightly modified to run with GNU Octave.
[ps,ix] = dpsimplify(p,tol)
where p is a nxm matrix that contains n vertices in m dimensions.
For additional information on the algorithm follow this link
I have a mix of very different polygon shapes. When giving a large tolerance level, it works well for big geometries, but it this case the smaller ones are simplified to a line.
How can I avoid, polygons to be simplefied to a single line ?
Fast, efficient and simple. This algorithm does exactly what I need. Thanks!
Thanks for this routine. Here's a failure case:
The problem arises because you only consider the perpendicular distance from the simplified line. You need also to consider the actual distance from the end points when the original points lie to the left or right of the simplified line.
@Mehdi: Thanks for your input. This algorithm assumes all data to be valid, thus there is no treatment of outliers.
Thanks for sharing
test this data
Do you have any idea for tackling outliers(last point in this data)?
Works great, thank you!
@Antony37: Simplifyrec basically does one step shown here
It is called recursively so that the entire sequence shown in the picture is computed.
Can you explain the logic under the function 'simplifyrec'?
thanks for your answer. Iwill try it
unfortunately I do not have access to the mapping toolbox, so I cannot tell if the results will be the same for dpsimplify and reducem. In general, however, I think, you can replace reducem with this function.
I have got cell tracking algorithm for microcopy images as m-files.
Unfortunately this uses MathLabs function "reducem". But we don't have the maps toolbox this function belongs to. Do you have experience if your dpsimplify could repolace reducem?
I wanted to simplify a contour as exported from a piece of imaging software which was way oversampled. Your program completely plugged and played, perfect!
The file has been updated so that the function can handle polylines, where the first and last vertex have the same coordinates. Just wait a short time until the updated version from 22. August appears.
you are right. I'll fix that as soon as possible.
the implementation fails if start and end point of the given line are the same.
added m-file that runs with GNU Octave
Added some information in the description.
Removed a bug in calculating the second output argument. Improved handling of lines with only one segment.
only minor changes: added some comments and changed the link to more information since it was dead.
First, the algorithm can now handle nans in the vertex array. It assumes that nans in the array serve as separator of single polylines and treats each polyline/polygon separately.
algorithm works also for polygons (start and end point of the polyline are the same).
Create scripts with code, output, and formatted text in a single executable document.