我正在使用skimage库来定义图形节点和边缘,以描述某些图像。应用算法并绘制分段区域后,我意识到区域之一未标记。我的目标是标记所有区域并找出每个区域的所有邻居,但是我一直试图回答这个问题。衷心感谢您提供任何有用的信息。
import imageio
import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
from skimage.measure import regionprops
from skimage.segmentation import slic
from skimage.segmentation import mark_boundaries
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.2126, 0.7152, 0.0722])
image = imageio.imread(img_file_path)
segments_slic = slic(image, n_segments=250, compactness=100)
regions = regionprops(segments_slic, intensity_image=rgb2gray(image))
for props in regions:
cy, cx = props.centroid
plt.plot(cx, cy, 'ro')
plt.imshow(mark_boundaries(image, segments_slic))
plt.show()