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
42 changes: 41 additions & 1 deletion examples/image-segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,46 @@
"plt.imshow(multi_class_segmenter.mask)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Integration with ipywidgets\n",
"\n",
"To reduce friction in the labelling workflow you can construct controls for the currently selected class and whether to be in erasing mode using ipywidgets."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"\n",
"N_classes = 3\n",
"class_selector = widgets.Dropdown(options=list(range(1, N_classes + 1)), description=\"class\")\n",
"\n",
"def update(change):\n",
" multi_class_segmenter.current_class = class_selector.value\n",
" multi_class_segmenter.erasing = erasing_button.value\n",
"\n",
"erasing_button = widgets.Checkbox(value=False, description=\"Erasing\")\n",
"erasing_button.observe(update, names=\"value\")\n",
"\n",
"class_selector.observe(update, names=\"value\")\n",
"multi_class_segmenter = image_segmenter(image, nclasses=3, mask_alpha=0.76)\n",
"display(widgets.HBox([erasing_button, class_selector]))\n",
"display(multi_class_segmenter)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -241,7 +281,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.9.1"
}
},
"nbformat": 4,
Expand Down
8 changes: 7 additions & 1 deletion mpl_interactions/tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ def cb(**kwargs):
assert len(zoop) == 1

ctrls = Controls(beep=(0, 1), boop=(0, 1))
ctrls.register_callback(cb, "beep", eager=True)
ctrls.register_callback(cb, "beep", eager=False)
assert len(zoop) == 1

ctrls.controls["beep"].set_val(0.5)
assert len(zoop) == 2

ctrls.controls["boop"].set_val(0.5)
assert len(zoop) == 2