У меня есть несколько надсегментированных меток, и я пытаюсь соединить и объединить их, основываясь на относительном расстоянии их наконечников. Итак, в примере изображения здесь, я хочу объединить светло-зеленый и желтый сегмент в одну метку. Я пытался расширить, но это не учитывает тот факт, что я хочу соединять метки только на основании их расстояния до наконечника.
Я пытался использовать что-то вроде RAG, но я не думаю, что это работает из-за фон, который равен 0?
from skimage.filters import sobel
from skimage import graph
edges = sobel(labels)
rag = graph.rag_boundary(labels, edges)
out = graph.show_rag(labels, rag, image)
Может кто-нибудь помочь с этим? Я не уверен, что мне здесь чего-то не хватает, потому что я c, так как я совсем новичок в кодировании.
Изображение меток
Вот массив меток:
[[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 26
0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 0 29
0 0 0 0 0 0 0 0 0 28 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 26 26
0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 28 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 26 26
0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 28 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 26 26
0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 28 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 26 26
0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 28 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 26 26
0 0 0 0 0 0 0 0 0 0 0 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