gpt4 book ai didi

python - skimage 切片 : getting neighbouring segments

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:55 25 4
gpt4 key购买 nike

在 python sklearn 包的 skimage.segmentation 包中有一个超分辨率片段生成 (SLIC) 的很好的实现。

slic() 方法返回整数组标签。我的问题是如何获得彼此空间相邻的段?我想做的是使用这些段构建一个图形,边缘将连接最近的邻居。但是,我无法弄清楚如何获得段的直接邻居。

执行SLIC的python代码如下:

from skimage import io
from skimage.segmentation import slic
from skimage.segmentation import find_boundaries
# An image of dimensions 300, 300
image = img_as_float(io.imread("image.png"))

# call slic. This returns an numpy array which assigns to every
# pixel in the image an integer label
# So segments is a numpy array of shape (300, 300)
segments = slic(image, 100, sigma = 5)

# Now I want to know the neighbourhood segment for each super-pixel
# There is a method called find_boundaries which returns a boolean
# for every pixel to show if it is a boundary pixel or not.

b = find_boundaries(segments)

在这里,我被困住了。我想知道如何解析这个边界索引并找出给定的标签索引(比如 0),哪些标签索引与索引 0 的标签共享一个边界。有没有一种方法可以在不循环遍历边界数组的情况下有效地执行此操作对于每个标签索引?

最佳答案

我这样做的方法是构建一个图形,其中包含从每个像素到其左侧和底部像素(因此是 4 个邻域)的边,用它们的超像素编号标记它们并删除重复项。您可以在 my blog post 中找到代码和详细信息.

可以找到一些相关函数here ,认为他们没有很好的记录(还)。

关于python - skimage 切片 : getting neighbouring segments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26237580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com