基于网络流和引导误差校正的追踪器
项目描述
tracktour
tracktour
是一个基于网络流线性模型的简单对象追踪器。 tracktour
接收一个检测到的对象的数据框,并解决一个线性规划问题(目前使用Gurobi,但我们很快将添加开源求解器接口)以生成追踪结果。
tracktour
正在快速变化,其API将更改而无需弃用警告。
关于 tracktour
tracktour
是一个基于纯离散优化的追踪器。它以检测到的对象的坐标作为输入,并将这些对象随时间关联起来以创建完整的轨迹,包括分割。tracktour的唯一参数是 k
- 在下一帧中考虑的可能分配的邻居数量。使用此参数和非常简单的基于距离的成本,创建一个候选图,并将其传递给Gurobi进行求解。一旦解决,就会将检测到的对象和构成轨迹的边返回给用户进行检查。
安装
tracktour
作为可pip安装的Python包提供。在虚拟环境中运行 pip install tracktour
将安装所有必需的依赖项,但您需要一个单独的Gurobi Optimizer安装(说明 这里)。
tracktour
已与所有 Python 版本 >=3.8 进行了测试。
注意 - 如果您想使用 napari
可视化数据(例如,按照 Cell Tracking Challenge 示例),则需要单独安装它。
支持
请随时提出功能请求、错误报告、使用问题等。
用法
Tracker
对象是生成跟踪解决方案的接口。以下是具有显式定义的检测的玩具示例。
# define the coordinates of ten detections across three frames.
coords = [
(0, 50.0, 50.0),
(0, 40, 50),
(0, 30, 57),
(1, 50, 52),
(1, 38, 51),
(1, 29, 60),
(2, 52, 53),
(2, 37, 53),
(2, 28, 64),
]
coords = pd.DataFrame(coords, columns=["t", "y", "x"])
# initialize Tracker object
tracker = Tracker(
im_shape=(100, 100), # size of the image detections come from. Affects cost of detections appearing/disappearing
k_neighbours=2 # number of neighbours to consider for assignment in the next frame (default=10)
)
# solve
tracked = tracker.solve(coords)
Tracked
对象包含检测的副本(可能已重新索引),以及构成解决方案的边的 dataframe。在 tracked_edges
中的列 u
和 v
是对 tracked_detections
中的直接索引。
print(tracked.tracked_detections)
print(tracked.tracked_edges)
您可能希望将解决方案转换为 networkx 图,以便更容易地进行操作。
solution_graph = tracked.as_nx_digraph()
请参阅 玩具示例 以获取完整的脚本,以及 CTC 示例 以在 napari
中进行可视化。
提取检测
如果您从图像分割开始,可以使用 get_im_centers
或 extract_im_centers
函数。
如果您的分割已经加载到 numpy 数组中,请使用 extract_im_centers
。返回的 detections
DataFrame 可用于与 Tracker
一起使用。
detections, min_t, max_t, corners = extract_im_centers(segmentation)
如果您的分割是 Cell Tracking Challenge 格式,并且位于目录中的单个 tiff 文件中,请使用 get_im_centers
。这还将返回作为 numpy 数组的分割。
seg, detections, min_t, max_t, corners = get_im_centers('path/to/01_RES/')
注意:如果使用 ctc
工具,将为您提取检测。
Cell Tracking Challenge
如果您正在使用 Cell Tracking Challenge 格式的数据集,请参阅 示例笔记本 以生成和可视化轨迹。
您还可以在命令行中使用 CLI 提取检测、运行 tracktour 并以 CTC 格式保存输出。
# run tracktour with k-neighbours=8
$ tracktour ctc /path/to/seg/ /path/to/save/ -k 8
注意: Tracktour 最近提交给了 Cell Tracking Challenge。要使用特定版本的提交,请安装 tracktour==0.0.4
。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关 安装包 的更多信息。