用Python计算KDE轮廓的面积

问题描述

所以我通过以下方式在python中完成了KDE:

y = coords[:,1]   ## A set of y coordinates of the red points
x = coords[:,0]   ## A set of x coordinates of the red points
k = gaussian_kde(np.vstack([x,y]))
k.set_bandwidth(bw_method=k.factor / 2.)

xi,yi = np.mgrid[x.min():x.max():x.size**0.8*1j,y.min():y.max():y.size**0.8*1j]
zi = k(np.vstack([xi.flatten(),yi.flatten()]))

fig,ax = plt.subplots(1,1,figsize=(16,8))

for coord in coordsold:
  cv2.circle(sample,(coord[1],coord[0]),2,(220,0),1)

ax.contourf(yi,xi,zi.reshape(xi.shape),alpha=0.5)
    
ax.set_axis_off()
ax.imshow(sample)

我要弄清楚的是轮廓占据的区域。我以为也许可以将轮廓线变成多边形对象,然后以这种方式计算面积,但是我不确定。如果有人有一个聪明的解决方案,将不胜感激。

参见附件:

Contours around points

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...