我正在尝试沿着数组中以1表示的形状的边界获取点的ndarray。我尝试使用scipy.spatial.ConvexHull
,但由凸包创建的边界并未解决形状中间的孔(我也需要在孔周围形成边界)。我正在尝试从数组创建这种边界。如何计算形状中的孔?
import numpy as np
from skimage.measure import label, regionprops
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi, voronoi_plot_2d, ConvexHull
arr = np.array([
[1,1,1,1,1,1,0,0,0,1,0],
[1,1,1,1,1,1,0,0,0,1,0],
[1,1,0,0,0,1,1,1,1,1,0],
[1,1,0,1,1,1,1,1,0,0,0],
[1,1,1,1,1,1,0,0,0,0,0],
[0,1,1,1,1,0,0,0,0,0,0],])
coords = []
for x in range(arr.shape[0]):
for y in range(arr.shape[1]):
if arr[x][y] > 0:
tile = [x,y]
coords.append(tile)
# print("tile", tile)
coords = np.array(coords)
# print(coords)
hull = ConvexHull(coords)
plt.plot(coords[:,0], coords[:,1], 'o')
for simplex in hull.simplices:
plt.plot(coords[simplex, 0], coords[simplex, 1], 'k-')
plt.plot(coords[hull.vertices,0], coords[hull.vertices,1], 'r--', lw=2)
plt.plot(coords[hull.vertices[0],0], coords[hull.vertices[0],1], 'ro')
答案 0 :(得分:1)
这有点棘手,但是如果将零与正确的内核(v4或v8)进行卷积,则会得到外部加上边界,因此,如果对内部进行var as_tv = new DeviceParameter() {
Key = "testkey",
DeviceId = new Guid(),
Value = "Armed"
};
var asp = new ArmingStatusParameter();
if (DeviceValueTypedParameterConverter.TryConvert<ArmingStatuses>(as_tv, asp)) {
// work with asp
}
var po_tv = new DeviceParameter() {
Key = "testkey2",
DeviceId = new Guid(),
Value = "4/15/2019 17:36"
};
var pop = new PoweredOnStatusParameter();
if (DeviceValueTypedParameterConverter.TryConvert<DateTime>(po_tv, pop)) {
// work with pop
}
var v_tv = new DeviceParameter() {
Key = "testkey3",
DeviceId = new Guid(),
Value = "17"
};
var vp = new VoltageStatusParameter();
if (DeviceValueTypedParameterConverter.TryConvert<int>(v_tv, vp)) {
// work with vp
}
类运算你只会得到边境。这是一个示例:
and