Skip to content

Commit 9e031df

Browse files
authored
adding bounding-box column (#121)
1 parent 808e965 commit 9e031df

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/tracksdata/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class DefaultAttrKeys:
1818
Default key for time information.
1919
MASK : str
2020
Default key for node masks.
21+
BBOX : str
22+
Default key for node bounding boxes.
23+
For a 2D image, the bounding box is a tuple of (x_start, y_start, x_end, y_end).
24+
For a 3D image, the bounding box is a tuple of (x_start, y_start, z_start, x_end, y_end, z_end).
2125
SOLUTION : str
2226
Default key for solution information.
2327
TRACK_ID : str
@@ -50,6 +54,7 @@ class DefaultAttrKeys:
5054
NODE_ID = "node_id"
5155
T = "t"
5256
MASK = "mask"
57+
BBOX = "bbox"
5358
SOLUTION = "solution"
5459
TRACK_ID = "track_id"
5560

src/tracksdata/nodes/_regionprops.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ def _init_node_attrs(self, graph: BaseGraph, axis_names: list[str]) -> None:
120120
"""
121121
Initialize the node attributes for the graph.
122122
"""
123-
if DEFAULT_ATTR_KEYS.MASK not in graph.node_attr_keys:
124-
graph.add_node_attr_key(DEFAULT_ATTR_KEYS.MASK, None)
123+
for attr_key in [DEFAULT_ATTR_KEYS.MASK, DEFAULT_ATTR_KEYS.BBOX]:
124+
if attr_key not in graph.node_attr_keys:
125+
graph.add_node_attr_key(attr_key, None)
125126

126127
# initialize the attribute keys
127128
for attr_key in axis_names + self.attrs_keys():
@@ -288,6 +289,7 @@ def _nodes_per_time(
288289
attrs[prop] = getattr(obj, prop)
289290

290291
attrs[DEFAULT_ATTR_KEYS.MASK] = Mask(obj.image, obj.bbox)
292+
attrs[DEFAULT_ATTR_KEYS.BBOX] = np.asarray(obj.bbox, dtype=int)
291293
attrs[DEFAULT_ATTR_KEYS.T] = t
292294

293295
nodes_data.append(attrs)

src/tracksdata/nodes/_test/test_regionprops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ def test_regionprops_spacing() -> None:
252252

253253
# Check that nodes were added (spacing affects internal calculations)
254254
nodes_df = graph.node_attrs()
255+
255256
assert len(nodes_df) == 1
256257
assert "area" in nodes_df.columns
257258
assert DEFAULT_ATTR_KEYS.MASK in nodes_df.columns
259+
assert nodes_df[DEFAULT_ATTR_KEYS.BBOX].to_numpy().ndim == 2
258260

259261

260262
def test_regionprops_empty_labels() -> None:

0 commit comments

Comments
 (0)