我在一个显示2D图像的示例ASCII文件中有一组点.
我想估计这些点填充的总面积.在这个平面内有一些地方没有被任何点填满,因为这些区域已经被掩盖了.我认为估计该区域可能是实用的将是应用凹形船体 或alpha形状.我尝试了这种方法来找到合适的alpha值,并因此估计面积.
from shapely.ops import cascaded_union, polygonize
import shapely.geometry as geometry
from scipy.spatial import Delaunay
import numpy as np
import pylab as pl
from descartes import PolygonPatch
from matplotlib.collections import LineCollection
def plot_polygon(polygon):
fig = pl.figure(figsize=(10,10))
ax = fig.add_subplot(111)
margin = .3
x_min, y_min, x_max, y_max = polygon.bounds
ax.set_xlim([x_min-margin, x_max+margin])
ax.set_ylim([y_min-margin, y_max+margin])
patch = PolygonPatch(polygon, fc='#999999',
ec='#000000', fill=True,
zorder=-1)
ax.add_patch(patch)
return fig
def alpha_shape(points, alpha):
if len(points) < 4:
# …Run Code Online (Sandbox Code Playgroud)