【问题标题】:How to find the length of a path (curve) in a picture?如何找到图片中路径(曲线)的长度?
【发布时间】:2014-12-25 14:44:39
【问题描述】:

我希望能够找到图片中路径的长度,这可能是一条蠕虫、一根卷曲的头发、亚马逊河等的长度。考虑这张亚马逊河图片:

我试图在二值化后制作我的图片的骨架,但问题是骨架(通过两种方法获得)有许多小分支,导致它们的面积远远超过路径的大致长度。我使用scikit-image 来做到这一点。这是代码和结果:

from skimage.filter import threshold_otsu
from skimage import io
from skimage.filter.rank import median
from skimage.morphology import disk,skeletonize,medial_axis,remove_small_objects
import matplotlib.pyplot as plt


input_image = io.imread('Amazon-river2.jpg',
                    as_grey=True, plugin=None, flatten=None)
image = median(input_image, disk(15)) 

thresh = threshold_otsu(image)
image = image < thresh

skel1=skeletonize(image)
skel2=medial_axis(image)

min_size=sum(sum(skel1))/2

remove_small_objects(skel1,min_size=min_size,connectivity=5,in_place=True)

remove_small_objects(skel2,min_size=min_size,connectivity=5,in_place=True)


fig2, ax = plt.subplots(2, 2, figsize=(24, 12))

ax[0,0].imshow(input_image,cmap=plt.cm.gray)
ax[0,0].set_title('Input image')
ax[0,0].axis('image')
ax[0,1].imshow(image, cmap=plt.cm.gray)
ax[0,1].set_title('Binary image')
ax[0,1].axis('image')
ax[1,0].imshow(skel1, cmap=plt.cm.gray)
ax[1,0].set_title('Skeleton')
ax[1,0].axis('image')
ax[1,1].imshow(skel2,cmap=plt.cm.gray)
ax[1,1].set_title('Sleleton - Medial axis')
ax[1,1].axis('image')

plt.show()


print ("Length 1: {0}".format(sum(sum(skel1))))
print ("Length 2: {0}".format(sum(sum(skel2))))

有解决这个问题的建议吗?测量弧长的任何其他想法?

【问题讨论】:

    标签: image-processing measure scikit-image


    【解决方案1】:

    在我看来,这是一个图,节点是端点并且它们通过路径连接。所以每个点都可能(或不)连接到任何其他点,您需要找到最长的路径。

    所以,您需要找到所有端点,从每个端点开始迭代,直到到达另一个端点。完成所有点后,您可以走最长的路!!!

    希望对你有帮助

    【讨论】:

    • 我想过!但这是一件非常困难的事情,因为你应该考虑你做出的关于走一条或另一条路径的决定的所有点,这就像一棵决策树。知道如何创建代码来执行此操作吗?
    【解决方案2】:

    试试下面的

    1. 在 R 或 B 通道上执行颜色分割,而不是 RGB->灰色
    2. 不要使用 graythresh Otsu,而是手动设置阈值或使用 multithresh Otsu(python 中也应该有)
    3. 在对二值图像进行骨架化之前执行以下形态学操作:侵蚀 -> 细化 -> 区域开放。这应该会消除孤岛。

    虽然skeletonize 总会有这样的问题,但你可以在二进制上进行精明的边缘检测。在每条边上执行跟随Arc length

    【讨论】:

      【解决方案3】:

      完全同意Yaron Kahanovitch的建议,我认为NetworkX应该能够完成计算最长轨迹/路线的工作,但是如何自动提取端点或交叉点作为节点并计算加权距离边缘仍然在苦苦挣扎和完成具有挑战性的任务。

      因此,我只发了another question on stackoverflow,希望有极客可以给我们宝贵的建议。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-01
        • 1970-01-01
        • 2022-01-19
        相关资源
        最近更新 更多