1
votes

I want to detect the boundary of my set of points. I tried Delaunay triangulation from scipy spatial, but I get this:enter image description here

And when I perform alpha shape from those triangles, I can't get the boundary of the set of points. So I think that I should use constrained Delaunay triangulation. I choose the triangle library to perform this. But the trouble is that I don't know what to feed to the function triangle.triangulate(tri, opts=''). I feed all my set of points that I change into dictionary but it returns my set of points. So anyone can help me to use this function or another alternative to perform the contour detection? Thanks

2

2 Answers

1
votes

I use another library for my purpose: shapely. Here is how to use it to triangulate a concave object:

from shapely.geometry import MultiPoint
from shapely.ops import triangulate
points=MultiPoint(data)
triangles = triangulate(points)
0
votes

I don't know about the triangle library, but you can use an alternative to perform this.

It is a widespread problem, and you can get a simple code to solve this. This problem, in the algorithms, is also known as Convex hull, and there is a class available in scipy.

The code follows below, with the comments.

#imports
from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt

## Init graphics
axis = plt.gca(); axis.cla();

#Get points sample
points = np.random.rand(20, 2)

#get Convex hull instance for the points set
hull = ConvexHull(points)

#plor the points
plt.plot(points[:,0], points[:,1], 'v')

#Get and plot the boundary
for simplex in hull.simplices:
    axis.plot(points[simplex, 0], points[simplex, 1], 'r-')

The result graph can be seen soon after:

enter image description here

REFs: