Skip to content

Commit

Permalink
Expose ctc to napari util
Browse files Browse the repository at this point in the history
  • Loading branch information
bentaculum committed Jun 4, 2024
1 parent b87710e commit 2c504f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions trackastra/tracking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
track_greedy,
)
from .utils import (
ctc_to_napari_tracks,
graph_to_ctc,
graph_to_napari_tracks,
linear_chains,
Expand Down
16 changes: 9 additions & 7 deletions trackastra/tracking/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class FoundTracks(Exception):
pass


def ctc_to_napari_tracks(segmentation: np.ndarray, man_track: np.ndarray):
def ctc_to_napari_tracks(segmentation: np.ndarray, man_track: pd.DataFrame):
"""Convert tracks in CTC format to tracks in napari format.
Args:
segmentation:
Dimensions: time, spatial_0, ... , spatial_n
segmentation: Dims time, spatial_0, ... , spatial_n
man_track: columns id, start, end, parent
"""
tracks = []
for t, frame in tqdm(
Expand All @@ -36,7 +36,7 @@ def ctc_to_napari_tracks(segmentation: np.ndarray, man_track: np.ndarray):

tracks_graph = {}
for idx, _, _, parent in tqdm(
man_track,
man_track.to_numpy(),
desc="Converting CTC to napari tracks",
leave=False,
):
Expand Down Expand Up @@ -161,8 +161,7 @@ def graph_to_napari_tracks(
for i, cs in enumerate(chains):
label = i + 1
labels.append(label)
# start nodes of dividing tracks include the parent
start, end = cs[0], cs[-1]
end = cs[-1]
track_end_to_track_id[end] = label

tracks = []
Expand All @@ -173,8 +172,11 @@ def graph_to_napari_tracks(
start = cs[0]
if start in track_end_to_track_id:
tracks_graph[label] = track_end_to_track_id[start]
nodes = cs[1:]
else:
nodes = cs

for c in cs:
for c in nodes:
node = graph.nodes[c]
t = node["time"]
coord = node["coords"]
Expand Down

0 comments on commit 2c504f7

Please sign in to comment.