From 521f75e1129f395df30a52513d535dbd26ae70ca Mon Sep 17 00:00:00 2001
From: Felipe Delestro Matos <fima@pop-os.localdomain>
Date: Tue, 5 Mar 2024 11:34:42 +0100
Subject: [PATCH] Example notebook for annotation tool

---
 docs/notebooks/annotation_tool.ipynb | 53 ++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/docs/notebooks/annotation_tool.ipynb b/docs/notebooks/annotation_tool.ipynb
index 9089f962..777be86c 100644
--- a/docs/notebooks/annotation_tool.ipynb
+++ b/docs/notebooks/annotation_tool.ipynb
@@ -7,19 +7,60 @@
    "outputs": [],
    "source": [
     "import qim3d\n",
-    "from scipy import ndimage\n",
     "import matplotlib.pyplot as plt\n",
-    "qim3d.io.logger.level(\"info\")\n",
     "\n",
     "# Load example image\n",
-    "img = qim3d.examples.bone_128x128x128\n",
+    "vol = qim3d.examples.bone_128x128x128\n",
     "\n",
     "# Start annotation tool\n",
-    "interface = qim3d.gui.annotation_tool.Interface()\n",
+    "annotation_tool = qim3d.gui.annotation_tool.Interface()\n",
     "\n",
     "# We can directly pass the image we loaded to the interface\n",
-    "#interface.launch()\n",
-    "interface.launch(ndimage.zoom(img[0], 3, order=0))"
+    "app = annotation_tool.launch(vol[0], server_name=\"10.197.104.229\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "annotation_tool.get_result()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "%matplotlib inline\n",
+    "import matplotlib.pyplot as plt\n",
+    "from IPython.display import clear_output\n",
+    "import numpy as np\n",
+    "import time\n",
+    "\n",
+    "while True:\n",
+    "    clear_output(wait=True)    \n",
+    "    masks_dict = annotation_tool.get_result()\n",
+    "    if len(masks_dict) == 0:\n",
+    "        masks_dict[\"No mask\"] = np.zeros((32,32))\n",
+    "    \n",
+    "    fig, axs = plt.subplots(1, len(masks_dict), figsize=(8,3))\n",
+    "\n",
+    "    if len(masks_dict) == 1:\n",
+    "        axs = [axs]\n",
+    "    for idx, (name, mask) in enumerate(masks_dict.items()):\n",
+    "\n",
+    "        axs[idx].imshow(mask, cmap='gray', interpolation='none')\n",
+    "        axs[idx].set_title(name)\n",
+    "        axs[idx].axis('off')\n",
+    "    \n",
+    "    plt.tight_layout()\n",
+    "\n",
+    "    \n",
+    "    plt.show()\n",
+    "    time.sleep(2)"
    ]
   }
  ],
-- 
GitLab