|
16 | 16 |
|
17 | 17 |
|
18 | 18 | @magicgui(call_button="Segment Object [S]") |
19 | | -def segment_wigdet(v: Viewer): |
| 19 | +def _segment_widget(v: Viewer) -> None: |
20 | 20 | # get the current box and point prompts |
21 | 21 | boxes = vutil.prompt_layer_to_boxes(v.layers["box_prompts"]) |
22 | 22 | points, labels = vutil.prompt_layer_to_points(v.layers["prompts"]) |
@@ -60,14 +60,14 @@ def _changed_param(amg, **params): |
60 | 60 |
|
61 | 61 |
|
62 | 62 | @magicgui(call_button="Automatic Segmentation") |
63 | | -def autosegment_widget( |
| 63 | +def _autosegment_widget( |
64 | 64 | v: Viewer, |
65 | 65 | with_background: bool = True, |
66 | 66 | pred_iou_thresh: float = 0.88, |
67 | 67 | stability_score_thresh: float = 0.95, |
68 | 68 | min_initial_size: int = 10, |
69 | 69 | box_extension: float = 0.05, |
70 | | -): |
| 70 | +) -> None: |
71 | 71 | global AMG |
72 | 72 | is_tiled = IMAGE_EMBEDDINGS["input_size"] is None |
73 | 73 | param_changed = _changed_param( |
@@ -150,24 +150,22 @@ def _initialize_viewer(raw, segmentation_result, tile_shape, show_embeddings): |
150 | 150 | prompt_widget = vutil.create_prompt_menu(prompts, labels) |
151 | 151 | v.window.add_dock_widget(prompt_widget) |
152 | 152 |
|
153 | | - # (optional) auto-segmentation functionality |
154 | | - v.window.add_dock_widget(autosegment_widget) |
155 | | - |
156 | | - v.window.add_dock_widget(segment_wigdet) |
157 | | - v.window.add_dock_widget(vutil.commit_segmentation_widget) |
158 | | - v.window.add_dock_widget(vutil.clear_widget) |
| 153 | + v.window.add_dock_widget(_autosegment_widget) |
| 154 | + v.window.add_dock_widget(_segment_widget) |
| 155 | + v.window.add_dock_widget(vutil._commit_segmentation_widget) |
| 156 | + v.window.add_dock_widget(vutil._clear_widget) |
159 | 157 |
|
160 | 158 | # |
161 | 159 | # key bindings |
162 | 160 | # |
163 | 161 |
|
164 | 162 | @v.bind_key("s") |
165 | 163 | def _segmet(v): |
166 | | - segment_wigdet(v) |
| 164 | + _segment_widget(v) |
167 | 165 |
|
168 | 166 | @v.bind_key("c") |
169 | 167 | def _commit(v): |
170 | | - vutil.commit_segmentation_widget(v) |
| 168 | + vutil._commit_segmentation_widget(v) |
171 | 169 |
|
172 | 170 | @v.bind_key("t") |
173 | 171 | def _toggle_label(event=None): |
@@ -206,7 +204,30 @@ def annotator_2d( |
206 | 204 | v: Optional[Viewer] = None, |
207 | 205 | predictor: Optional[SamPredictor] = None, |
208 | 206 | ) -> Optional[Viewer]: |
209 | | - """ |
| 207 | + """The 2d annotation tool. |
| 208 | +
|
| 209 | + Args: |
| 210 | + raw: The image data. |
| 211 | + embedding_path: Filepath where to save the embeddings. |
| 212 | + show_embeddings: Show PCA visualization of the image embeddings. |
| 213 | + This can be helpful to judge how well Segment Anything works for your data, |
| 214 | + and which objects can be segmented. |
| 215 | + segmentation_result: An initial segmentation to load. |
| 216 | + This can be used to correct segmentations with Segment Anything or to save and load progress. |
| 217 | + The segmentation will be loaded as the 'committed_objects' layer. |
| 218 | + model_type: The Segment Anything model to use. For details on the available models check out |
| 219 | + https://computational-cell-analytics.github.io/micro-sam/micro_sam.html#finetuned-models. |
| 220 | + tile_shape: Shape of tiles for tiled embedding prediction. |
| 221 | + If `None` then the whole image is passed to Segment Anything. |
| 222 | + halo: Shape of the overlap between tiles, which is needed to segment objects on tile boarders. |
| 223 | + return_viewer: Whether to return the napari viewer to further modify it before starting the tool. |
| 224 | + v: The viewer to which the SegmentAnything functionality should be added. |
| 225 | + This enables using a pre-initialized viewer, for example in `sam_annotator.image_series_annotator`. |
| 226 | + predictor: The Segment Anything model. Passing this enables using fully custom models. |
| 227 | + If you pass `predictor` then `model_type` will be ignored. |
| 228 | +
|
| 229 | + Returns: |
| 230 | + The napari viewer, only returned if `return_viewer=True`. |
210 | 231 | """ |
211 | 232 | # for access to the predictor and the image embeddings in the widgets |
212 | 233 | global PREDICTOR, IMAGE_EMBEDDINGS, AMG |
@@ -245,6 +266,7 @@ def annotator_2d( |
245 | 266 |
|
246 | 267 |
|
247 | 268 | def main(): |
| 269 | + """@private""" |
248 | 270 | parser = vutil._initialize_parser(description="Run interactive segmentation for an image.") |
249 | 271 | args = parser.parse_args() |
250 | 272 | raw = util.load_image_data(args.input, key=args.key) |
|
0 commit comments