77from .. import util
88from ..segment_from_prompts import segment_from_mask , segment_from_points
99from ..visualization import compute_pca
10- from .util import create_prompt_menu , prompt_layer_to_points
10+ from .util import commit_segmentation_widget , create_prompt_menu , prompt_layer_to_points
1111
1212COLOR_CYCLE = ["#00FF00" , "#FF0000" ]
1313
@@ -160,27 +160,9 @@ def segment_volume_widget(v: Viewer, iou_threshold: float = 0.8, method: str = "
160160 v .layers ["current_object" ].refresh ()
161161
162162
163- @magicgui (call_button = "Commit [C]" )
164- def commit_widget (v : Viewer ):
165- global NEXT_ID
166- seg = v .layers ["current_object" ].data
167-
168- v .layers ["committed_objects" ].data [seg == 1 ] = NEXT_ID
169- v .layers ["committed_objects" ].refresh ()
170-
171- shape = v .layers ["raw" ].data .shape
172- v .layers ["current_object" ].data = np .zeros (shape , dtype = "uint32" )
173- v .layers ["current_object" ].refresh ()
174-
175- v .layers ["prompts" ].data = []
176- v .layers ["prompts" ].refresh ()
177- NEXT_ID += 1
178-
179-
180- # TODO enable passing also an initial segmentation
181163def annotator_3d (raw , embedding_path = None , show_embeddings = False , segmentation_result = None ):
182164 # for access to the predictor and the image embeddings in the widgets
183- global PREDICTOR , IMAGE_EMBEDDINGS , NEXT_ID
165+ global PREDICTOR , IMAGE_EMBEDDINGS
184166 PREDICTOR = util .get_sam_model ()
185167 IMAGE_EMBEDDINGS = util .precompute_image_embeddings (PREDICTOR , raw , save_path = embedding_path )
186168
@@ -193,11 +175,9 @@ def annotator_3d(raw, embedding_path=None, show_embeddings=False, segmentation_r
193175 v .add_image (raw )
194176 if segmentation_result is None :
195177 v .add_labels (data = np .zeros (raw .shape , dtype = "uint32" ), name = "committed_objects" )
196- NEXT_ID = 1
197178 else :
198179 assert segmentation_result .shape == raw .shape
199180 v .add_labels (data = segmentation_result , name = "committed_objects" )
200- NEXT_ID = int (segmentation_result .max ()) + 1
201181 v .add_labels (data = np .zeros (raw .shape , dtype = "uint32" ), name = "current_object" )
202182
203183 # show the PCA of the image embeddings
@@ -234,7 +214,7 @@ def annotator_3d(raw, embedding_path=None, show_embeddings=False, segmentation_r
234214 # v.bind_key("s", segment_slice_wigdet) FIXME this causes an issue with all shortcuts
235215
236216 v .window .add_dock_widget (segment_volume_widget )
237- v .window .add_dock_widget (commit_widget )
217+ v .window .add_dock_widget (commit_segmentation_widget )
238218
239219 #
240220 # key bindings
@@ -250,7 +230,7 @@ def _seg_volume(v):
250230
251231 @v .bind_key ("c" )
252232 def _commit (v ):
253- commit_widget (v )
233+ commit_segmentation_widget (v )
254234
255235 @v .bind_key ("t" )
256236 def toggle_label (event = None ):
0 commit comments