如何在图片中找到路径(曲线)的长度? [英] How to find the length of a path (curve) in a picture?

查看:665
本文介绍了如何在图片中找到路径(曲线)的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to be able to find the length of a path in a picture, this could be the length of a worm, a curly human hair, Amazon river, etc. Consider this Amazon river picture:

我试图制作骨架我的图片在二值化后,但问题是骨架(通过两种方法获得)有许多小分支,导致它们的区域远远超过路径的近似长度。我使用 scikit-image 来执行此操作。以下是代码和结果:

I tried to make an skeleton of my picture after its binarization, but the problem is that the skeletons (obtained by two methods) have many small branches that causes their area to be much more than the approximate length of the path. I used scikit-image to do this. Here's the code and results:

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))))

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

Any suggestions to solve this problem? Any other idea to measure the length of an arc ?

推荐答案

正如我所看到的,这是节点结束的图表点和它们通过路径连接。所以每个点可能(或没有)连接到任何其他点,你需要找到最长的路径。

As I see it, this is a graph were the nodes are end points and they are connected by path. so every point may (or not) connected to any other point, and you need need to find the longest path.

所以,你需要找到所有的终点,从每个终点开始迭代,直到你到达另一个终点。在为所有积分做完之后你可以走最长路径!!!

so, you need to find all end points, from each end point start to iterate until you get to another end point. after doing it for all points you can take the longest path!!!

希望有帮助

这篇关于如何在图片中找到路径(曲线)的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆