Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/tracksdata/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class DefaultAttrKeys:
Default key for time information.
MASK : str
Default key for node masks.
BBOX : str
Default key for node bounding boxes.
For a 2D image, the bounding box is a tuple of (x_start, y_start, x_end, y_end).
For a 3D image, the bounding box is a tuple of (x_start, y_start, z_start, x_end, y_end, z_end).
SOLUTION : str
Default key for solution information.
TRACK_ID : str
Expand Down Expand Up @@ -50,6 +54,7 @@ class DefaultAttrKeys:
NODE_ID = "node_id"
T = "t"
MASK = "mask"
BBOX = "bbox"
SOLUTION = "solution"
TRACK_ID = "track_id"

Expand Down
6 changes: 4 additions & 2 deletions src/tracksdata/nodes/_regionprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ def _init_node_attrs(self, graph: BaseGraph, axis_names: list[str]) -> None:
"""
Initialize the node attributes for the graph.
"""
if DEFAULT_ATTR_KEYS.MASK not in graph.node_attr_keys:
graph.add_node_attr_key(DEFAULT_ATTR_KEYS.MASK, None)
for attr_key in [DEFAULT_ATTR_KEYS.MASK, DEFAULT_ATTR_KEYS.BBOX]:
if attr_key not in graph.node_attr_keys:
graph.add_node_attr_key(attr_key, None)

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

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

nodes_data.append(attrs)
Expand Down
2 changes: 2 additions & 0 deletions src/tracksdata/nodes/_test/test_regionprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ def test_regionprops_spacing() -> None:

# Check that nodes were added (spacing affects internal calculations)
nodes_df = graph.node_attrs()

assert len(nodes_df) == 1
assert "area" in nodes_df.columns
assert DEFAULT_ATTR_KEYS.MASK in nodes_df.columns
assert nodes_df[DEFAULT_ATTR_KEYS.BBOX].to_numpy().ndim == 2


def test_regionprops_empty_labels() -> None:
Expand Down