如何在python中获得voronoi边缘图
我想为点注释(原子核位置的二进制图像)创建一个voronoi边图。我使用中的代码创建voronoi边缘图,但结果显示在图像中。我只需要voronoi边。下面是代码 Voronoi边图如何在python中获得voronoi边缘图,python,voronoi,Python,Voronoi,我想为点注释(原子核位置的二进制图像)创建一个voronoi边图。我使用中的代码创建voronoi边缘图,但结果显示在图像中。我只需要voronoi边。下面是代码 Voronoi边图 def viro(img): label_point=img h, w = label_point.shape points = np.argwhere(label_point>0) vor = Voronoi(points) regions, vertices = voronoi_finite_p
def viro(img):
label_point=img
h, w = label_point.shape
points = np.argwhere(label_point>0)
vor = Voronoi(points)
regions, vertices = voronoi_finite_polygons_2d(vor)
box = Polygon([[0, 0], [0, w], [h, w], [h, 0]])
region_masks = np.zeros((h, w), dtype=np.int16)
edges = np.zeros((h, w), dtype=np.bool)
count = 1
masks= np.zeros((h, w), dtype=np.bool)
for region in regions:
polygon = vertices[region]
# Clipping polygon
poly = Polygon(polygon)
poly = poly.intersection(box)
polygon = np.array([list(p) for p in poly.exterior.coords])
mask = poly2mask(polygon[:, 0], polygon[:, 1], (h, w))
edge = mask * (~morphology.erosion(mask, morphology.disk(1)))
edges += edge
region_masks[mask] = count
count += 1
# fuse Voronoi edge and dilated points
label_point_dilated = morphology.dilation(label_point, morphology.disk(1))
label_vor = np.zeros((h, w, 3), dtype=np.uint8)
label_vor[:, :, 0] = (edges > 0).astype(np.uint8) * 255
label_vor[:, :, 1] = (label_point_dilated > 0).astype(np.uint8) * 255
return label_vor
我碰巧发现了这个问题。实际上,问题在于二值图像,因为它是核位置的基本事实,半径为3个像素,因此,它没有获得一个核的单坐标(单像素),而是检索了三个坐标值,因为每个核位置的半径为3个像素,从而给出了结果图像