Skip to content

Commit

Permalink
Merge pull request #102 from anwai98/u2-tracking-metrics
Browse files Browse the repository at this point in the history
Minor update to scripts to add missing tracked objects
  • Loading branch information
constantinpape authored Aug 27, 2024
2 parents 1ae2ace + 979e9c8 commit 2c4cb9b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 12 deletions.
67 changes: 62 additions & 5 deletions scripts/automatic_tracks.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
,Cell_ID,Start,End,Parent_ID
0,1,0,0,0
1,2,1,6,0
1,2,1,6,1
2,10,1,1,1
3,3,7,14,0
3,3,7,14,2
4,8,7,8,2
5,4,15,15,3
6,6,15,23,3
Expand All @@ -22,11 +22,11 @@
20,45,4,23,44
21,47,4,23,44
22,50,0,4,0
23,51,5,13,0
23,51,5,13,50
24,62,5,23,50
25,52,14,15,51
26,54,14,14,0
27,55,15,16,0
26,54,14,14,51
27,55,15,16,54
28,60,15,15,54
29,56,17,22,55
30,58,17,23,55
Expand Down Expand Up @@ -57,3 +57,60 @@
55,125,4,13,0
56,126,14,17,125
57,128,14,23,125
58,11,0,23,0
59,12,0,23,0
60,13,0,23,0
61,14,0,20,0
62,15,0,23,0
63,16,0,23,0
64,17,0,23,0
65,18,0,23,0
66,23,0,23,0
67,24,0,23,0
68,29,0,23,0
69,34,0,23,0
70,35,0,23,0
71,36,0,3,0
72,37,0,23,0
73,38,0,23,0
74,39,0,23,0
75,48,0,23,0
76,49,0,23,0
77,67,0,12,0
78,68,0,23,0
79,69,0,23,0
80,70,0,23,0
81,75,0,23,0
82,80,0,23,0
83,81,0,23,0
84,82,0,23,0
85,83,0,23,0
86,84,0,18,0
87,85,0,23,0
88,86,0,23,0
89,91,0,23,0
90,92,0,23,0
91,93,0,23,0
92,94,0,23,0
93,95,0,1,0
94,100,0,23,0
95,101,0,23,0
96,102,0,23,0
97,107,0,23,0
98,108,0,23,0
99,109,0,23,0
100,110,0,23,0
101,115,0,23,0
102,116,2,23,0
103,121,2,23,0
104,122,3,20,0
105,123,3,23,0
106,124,4,23,0
107,129,6,23,0
108,130,8,9,0
109,131,8,19,0
110,132,9,17,0
111,133,13,23,0
112,134,18,22,0
113,135,19,23,0
114,136,21,23,0
29 changes: 22 additions & 7 deletions scripts/measure_for_automatic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

import json
import h5py
import numpy as np
import pandas as pd
import imageio.v3 as imageio
Expand All @@ -28,12 +27,17 @@ def _get_tracks_to_isbi():
parent_id = int(parent_id)
frames = np.where(segmentation == parent_id)[0]

if parent_id in track_info:
parent_val = track_info[parent_id]['parent']
else:
parent_val = None

# store the parent's track information
track_info[parent_id] = {
'frames': list(np.unique(frames)),
'daughters': list(daughter_ids),
'frame_div': frames.max() + 1,
'parent': None,
'parent': parent_val,
'label': parent_id,
}

Expand All @@ -48,6 +52,20 @@ def _get_tracks_to_isbi():
'label': daughter_id
}

# now, the next step is to store track info for objects that did not split.
for gt_id in np.unique(segmentation)[1:]:
if gt_id in track_info:
continue

frames = np.where(segmentation == gt_id)[0]
track_info[gt_id] = {
'frames': list(np.unique(frames)),
'daughters': [],
'frame_div': None,
'parent': None,
'label': gt_id,
}

from deepcell_tracking import isbi_utils
track_df = isbi_utils.trk_to_isbi(track_info)
track_df.to_csv("automatic_tracks.csv")
Expand All @@ -57,7 +75,6 @@ def _get_tracks_to_isbi():
def _get_tracks_df():
tracks_path = "automatic_tracks.csv"
segmentation = imageio.imread(os.path.join(ROOT, "tracking_result.tif"))
breakpoint()
if os.path.exists(tracks_path):
track_df = pd.read_csv(tracks_path)
else:
Expand All @@ -67,19 +84,17 @@ def _get_tracks_df():

def _get_metrics_for_autotrack(segmentation, seg_df):
# NOTE: for ground-truth
with h5py.File(os.path.join(ROOT, "tracking_micro_sam.h5")) as f:
gt = f['labels'][:]

gt = imageio.imread(os.path.join(ROOT, "tracking_gt_corrected.tif"))
gt_nodes = _get_node_attributes(gt)
gt_df = pd.read_csv("gt_tracks.csv")
gt_G = ctc_to_graph(gt_df, gt_nodes)
_check_ctc(gt_df, gt_nodes, gt)
gt_T = TrackingGraph(gt_G, segmentation=gt, name="DynamicNuclearNet-GT")

# NOTE: for segmentation results
# calculate node attributes for each detection
seg_nodes = _get_node_attributes(segmentation)
seg_G = ctc_to_graph(seg_df, seg_nodes)
_check_ctc(seg_df, seg_nodes, segmentation)
seg_T = TrackingGraph(seg_G, segmentation=segmentation, name="DynamicNuclearNet-autotracking")

ctc_results = run_metrics(
Expand Down

0 comments on commit 2c4cb9b

Please sign in to comment.