Skip to content

Commit 47807f8

Browse files
Add divison label to tracking annotator WIP
1 parent b17db87 commit 47807f8

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

micro_sam/sam_annotator/annotator_2d.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from .. import util
88
from ..visualization import compute_pca
99
from ..segment_from_prompts import segment_from_points
10-
from .util import commit_segmentation_widget, create_prompt_menu, prompt_layer_to_points
11-
12-
COLOR_CYCLE = ["#00FF00", "#FF0000"]
10+
from .util import commit_segmentation_widget, create_prompt_menu, prompt_layer_to_points, LABEL_COLOR_CYCLE
1311

1412

1513
@magicgui(call_button="Segment Object [S]")
@@ -53,7 +51,7 @@ def annotator_2d(raw, embedding_path=None, show_embeddings=False, segmentation_r
5351
name="prompts",
5452
properties={"label": labels},
5553
edge_color="label",
56-
edge_color_cycle=COLOR_CYCLE,
54+
edge_color_cycle=LABEL_COLOR_CYCLE,
5755
symbol="o",
5856
face_color="transparent",
5957
edge_width=0.5,

micro_sam/sam_annotator/annotator_3d.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from .. import util
99
from ..segment_from_prompts import segment_from_mask, segment_from_points
1010
from ..visualization import compute_pca
11-
from .util import commit_segmentation_widget, create_prompt_menu, prompt_layer_to_points, segment_slices_with_prompts
12-
13-
COLOR_CYCLE = ["#00FF00", "#FF0000"]
11+
from .util import (commit_segmentation_widget, create_prompt_menu,
12+
prompt_layer_to_points, segment_slices_with_prompts, LABEL_COLOR_CYCLE)
1413

1514

1615
#
@@ -178,7 +177,7 @@ def annotator_3d(raw, embedding_path=None, show_embeddings=False, segmentation_r
178177
name="prompts",
179178
properties={"label": labels},
180179
edge_color="label",
181-
edge_color_cycle=COLOR_CYCLE,
180+
edge_color_cycle=LABEL_COLOR_CYCLE,
182181
symbol="o",
183182
face_color="transparent",
184183
edge_width=0.5,

micro_sam/sam_annotator/annotator_tracking.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from .. import util
1313
from ..segment_from_prompts import segment_from_mask, segment_from_points
1414
from ..visualization import compute_pca
15-
from .util import create_prompt_menu, prompt_layer_to_points, segment_slices_with_prompts
15+
from .util import create_prompt_menu, prompt_layer_to_points, segment_slices_with_prompts, LABEL_COLOR_CYCLE
1616

17-
COLOR_CYCLE = ["#00FF00", "#FF0000"]
17+
# Magenta and Cyan
18+
STATE_COLOR_CYCLE = ["#FF00FF", "#00FFFF"]
1819

1920

2021
#
@@ -191,21 +192,23 @@ def annotator_tracking(raw, embedding_path=None, show_embeddings=False):
191192
#
192193
# add the widgets
193194
#
194-
# TODO add the division labels
195195
labels = ["positive", "negative"]
196+
state_labels = ["division", "track"]
196197
prompts = v.add_points(
197198
data=[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], # FIXME workaround
198199
name="prompts",
199-
properties={"label": labels},
200+
properties={"label": labels, "state": state_labels},
200201
edge_color="label",
201-
edge_color_cycle=COLOR_CYCLE,
202+
edge_color_cycle=LABEL_COLOR_CYCLE,
202203
symbol="o",
203-
face_color="transparent",
204-
edge_width=0.5, # FIXME workaround
204+
face_color="state",
205+
face_color_cycle=STATE_COLOR_CYCLE,
206+
edge_width=0.4,
205207
size=12,
206208
ndim=3,
207209
)
208210
prompts.edge_color_mode = "cycle"
211+
prompts.face_color_mode = "cycle"
209212

210213
#
211214
# add the widgets
@@ -216,6 +219,9 @@ def annotator_tracking(raw, embedding_path=None, show_embeddings=False):
216219
prompt_widget = create_prompt_menu(prompts, labels)
217220
v.window.add_dock_widget(prompt_widget)
218221

222+
state_widget = create_prompt_menu(prompts, state_labels, menu_name="state", label_name="state")
223+
v.window.add_dock_widget(state_widget)
224+
219225
v.window.add_dock_widget(segment_frame_wigdet)
220226
v.window.add_dock_widget(track_objet_widget)
221227

micro_sam/sam_annotator/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from ..segment_from_prompts import segment_from_points
88

9+
# Green and Red
10+
LABEL_COLOR_CYCLE = ["#00FF00", "#FF0000"]
11+
912

1013
@magicgui(call_button="Commit [C]")
1114
def commit_segmentation_widget(v: Viewer):
@@ -23,20 +26,20 @@ def commit_segmentation_widget(v: Viewer):
2326
v.layers["prompts"].refresh()
2427

2528

26-
def create_prompt_menu(points_layer, labels):
27-
label_menu = ComboBox(label="prompts", choices=labels)
29+
def create_prompt_menu(points_layer, labels, menu_name="prompt", label_name="label"):
30+
label_menu = ComboBox(label=menu_name, choices=labels)
2831
label_widget = Container(widgets=[label_menu])
2932

3033
def update_label_menu(event):
31-
new_label = str(points_layer.current_properties["label"][0])
34+
new_label = str(points_layer.current_properties[label_name][0])
3235
if new_label != label_menu.value:
3336
label_menu.value = new_label
3437

3538
points_layer.events.current_properties.connect(update_label_menu)
3639

3740
def label_changed(new_label):
3841
current_properties = points_layer.current_properties
39-
current_properties["label"] = np.array([new_label])
42+
current_properties[label_name] = np.array([new_label])
4043
points_layer.current_properties = current_properties
4144
points_layer.refresh_colors()
4245

0 commit comments

Comments
 (0)