SimplifyPath: Simplify a path

Description Usage Arguments Value Author(s) References Examples

View source: R/SimplifyPath.R

Description

This function takes a path and removes points that impact the shape of the path less than a tolerance value, which is a scaled measure of degree deviation from removing a path. It is based on an algorithm described by Latecki & Lakaemper.

Usage

1
2
3
4
5
SimplifyPath(path,
             tolerance = 0.075,
             truncate=F,
             faster = T, 
             verbose = F, plot = F)

Arguments

path

a 2-column matrix of x,y points

truncate

Number of digits to round values to. If FALSE (the default), there is no rounding. If another value, the value is used as the digits argument of round to use to truncate the precision of the path. This can help simplify the path by rounding to a known precision level.

tolerance

a tolerance threshold; any point that does not impact the shape of the path more than this is removed. For this, smaller values remove fewer points. Depending on the complexity of the path, values from 0.01 to 0.1 may be good starting points.

faster

If TRUE, this uses a faster point-trimming method. If T, it removes all points that have a K value equal to the minimum value, which can be many (for example, a bunch that are equal to 0). If F, it will only remove one one each round, which can be very slow.

verbose

if TRUE, will print out intermediate information during the shape evolution.

plot

if TRUE, will create a plot of the path and overlay the evolving simplified path.

Value

Returns a path with redundant points removed.

Author(s)

Shane T. Mueller and Brandon Perelman

References

See Mueller et al., (2016).
and
L. J. Latecki and R. Lakaemper. Convexity Rule for Shape Decomposition Based on Discrete Contour Evolution. Computer Vision and Image Understanding, vol. 73, pp. 441-454, 1999.
https://sites.google.com/a/mtu.edu/mapping/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
path <- cbind(1:100,exp(-(1:100-50)^2/80))
path2 <- SimplifyPath(path)


## Not run: 
plot(path)
plot(path2)
plot(path)
points(SimplifyPath(path,tolerance=.1),type="o",
        col="red",cex=1.2,lwd=2)
plot(path)
points(SimplifyPath(path,tolerance=.01,plot=TRUE),type="o",
        col="red",cex=1.2,lwd=2)
plot(path)
points(SimplifyPath(path,tolerance=.005,plot=TRUE),type="o",
        col="red",cex=1.2,lwd=2)

## End(Not run)

Example output



pathmapping documentation built on May 2, 2019, 4:20 a.m.