检测分割标签
问题描述:
我可以计算出使用skimage如下SLIC边界的边界像素:检测分割标签
def compute_superpixels(frame, num_pixels=100, std=5, iter_max=10,
connectivity=False, compactness=10.0):
return slic(frame, n_segments=num_pixels, sigma=std, max_iter=iter_max,
enforce_connectivity=connectivity, compactness=compactness)
现在,我想要做的就是形成每个标签的边界像素的索引。所以我的想法是让属于给定段的所有像素,然后检查哪些像素在所有两个方向的变化
def boundary_pixels(segments, index):
# Get all pixels having a given index
x, y = np.where(segments == index)
right = x + 1
# check we are in bounds
right_mask = right < segments.shape[0]
down = y + 1
down_mask = down < segments.shape[1]
left = x - 1
left_mask = left >= 0
up = y - 1
up_mask = up >= 0
neighbors_1 = np.union1d(right_n, down_n)
neighbors_2 = np.union1d(left_n, up_n)
neighbors = np.union1d(neighbors_1, neighbors_2)
# Not neighbours to ourselves
neighbors = np.delete(neighbors, np.where(neighbors == i))
然而,这一切我设法做的是让在4个方向邻居给定的标签。有人可以建议一些方法来实际获得标签边界上的所有像素。
答
我找到了自己的问题的答案。 skimage.segmentation包中的mark_boundaries正是我所需要的。
用法:
processed = mark_boundaries(frame, segments==some_segment)
这里帧是他当前图像帧和段是标签阵列。 some_segment是我们感兴趣的边界的标签整数索引。
答
您可以利用skimage.measure模块中可用的find_contours函数来查找边界上像素的坐标。一个例子可在find_contours.。接下来,您可以根据需要更改两个方向的更改。
+0
感谢您的回复。我设法使用了skimage.segmentation中的mark_contours函数。 – Luca 2015-02-08 13:34:43
也看看RegionProperties。 – 2015-02-09 01:06:02