关于如何使用 python 测量骨骼长度的想法
Ideas how to measure the length of a skeleton using python
申请后skeletonization on an image(),
我想用 python 测量最长的分支或骨架的脊柱。 ImageJ 有几个工具可以完成这项工作,其中一个是 Measure_Skeleton_length, another is AnalyzeSkeleton。 python?
中有任何工具或建议吗?
我不知道 python 工具,但从算法的角度来看,这是一种方法:
- 检测所有极值像素(分支上的最后一个像素,因此只有一个邻居的像素)
- 对于这些像素中的每一个,计算测地线距离图。
那么你在地图计算过程中找到的最大距离就是你想要的距离。第1点是基础编码,所以Python可以,但是第2点你得找个库
这是对原始问题的一个很晚的答复,但以防万一仍然有需要的人最终可能会阅读此 post。有一个名为 FilFinder
(pip install fil_finder
) 的用于分析骨架的很棒的 python 包,它优雅地解决了这个问题。下面是从他们的 tutorial
中采用的代码
import numpy as np
import cv2
import matplotlib.pyplot as plt
from fil_finder import FilFinder2D
import astropy.units as u
skeleton = ... #in numpy array format
fil = FilFinder2D(skeleton, distance=250 * u.pc, mask=skeleton)
fil.preprocess_image(flatten_percent=85)
fil.create_mask(border_masking=True, verbose=False,
use_existing_mask=True)
fil.medskel(verbose=False)
fil.analyze_skeletons(branch_thresh=40* u.pix, skel_thresh=10 * u.pix, prune_criteria='length')
plt.imshow(fil.skeleton, cmap='gray')
plt.contour(fil.skeleton_longpath, colors='r')
plt.axis('off')
plt.show()
输出
申请后skeletonization on an image(),
我想用 python 测量最长的分支或骨架的脊柱。 ImageJ 有几个工具可以完成这项工作,其中一个是 Measure_Skeleton_length, another is AnalyzeSkeleton。 python?
中有任何工具或建议吗?我不知道 python 工具,但从算法的角度来看,这是一种方法:
- 检测所有极值像素(分支上的最后一个像素,因此只有一个邻居的像素)
- 对于这些像素中的每一个,计算测地线距离图。
那么你在地图计算过程中找到的最大距离就是你想要的距离。第1点是基础编码,所以Python可以,但是第2点你得找个库
这是对原始问题的一个很晚的答复,但以防万一仍然有需要的人最终可能会阅读此 post。有一个名为 FilFinder
(pip install fil_finder
) 的用于分析骨架的很棒的 python 包,它优雅地解决了这个问题。下面是从他们的 tutorial
import numpy as np
import cv2
import matplotlib.pyplot as plt
from fil_finder import FilFinder2D
import astropy.units as u
skeleton = ... #in numpy array format
fil = FilFinder2D(skeleton, distance=250 * u.pc, mask=skeleton)
fil.preprocess_image(flatten_percent=85)
fil.create_mask(border_masking=True, verbose=False,
use_existing_mask=True)
fil.medskel(verbose=False)
fil.analyze_skeletons(branch_thresh=40* u.pix, skel_thresh=10 * u.pix, prune_criteria='length')
plt.imshow(fil.skeleton, cmap='gray')
plt.contour(fil.skeleton_longpath, colors='r')
plt.axis('off')
plt.show()
输出