【发布时间】:2020-10-29 18:19:33
【问题描述】:
我有一个轮廓,我想找到它的区域(后轮廓末端的图像是线索线,由蓝色的一组点描述)。我曾尝试为此使用 alphashape(见下文),但它对于我的目的来说效果不够好(图像上绿色轮廓的 alphashape 近似值)。我可以使用其他方法来获取此轮廓内的区域吗?
谢谢!
到目前为止,这是我的代码。 points 是我要执行此操作的所有单个轮廓的列表。
for cnum in np.arange(0,(len(points))):
cpoints_nan=points[cnum]
cpoints=[]
for i in np.arange(0, len(cpoints_nan)): #Get rid of nan pairs
if np.isnan(cpoints_nan[i][0]): #If current pair of points is [nan, nan]
continue
else: #If current pair of points is not nan, add to cpoints
cpoints.append([cpoints_nan[i][0][np.logical_not(np.isnan(cpoints_nan[i][0]))][0], cpoints_nan[i][1][np.logical_not(np.isnan(cpoints_nan[i][1]))][0]])
if len(cpoints)>3: #Need more than two points to use alphashape. Greater than 3 because for closed "loops" the last point is the first and so this will still just form a line rather than a polygon
alpha=alphashape.optimizealpha(cpoints)
hull = alphashape.alphashape(cpoints, alpha)
contour_areas.append(hull.area) #Get area inside contour
编辑:我看到的许多轮廓都是自相交的,所以这是一个额外的复杂层
【问题讨论】:
-
使用鞋矛公式:en.wikipedia.org/wiki/Shoelace_formula... 或将等高线点转换为具有面积属性的匀称多边形