Skip to content
Snippets Groups Projects
annotation_tool.ipynb 2.11 KiB
Newer Older
  • Learn to ignore specific revisions
  • {
     "cells": [
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "import qim3d\n",
        "import matplotlib.pyplot as plt\n",
    
    fima's avatar
    fima committed
        "\n",
        "# Load example image\n",
    
        "vol = qim3d.examples.bone_128x128x128\n",
    
        "\n",
        "# Start annotation tool\n",
    
        "annotation_tool = qim3d.gui.annotation_tool.Interface()\n",
    
        "\n",
        "# We can directly pass the image we loaded to the interface\n",
    
        "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)"
    
       ]
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "Python 3 (ipykernel)",
       "language": "python",
       "name": "python3"
      },
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
    
    fima's avatar
    fima committed
       "version": "3.11.5"
    
    fima's avatar
    fima committed
     "nbformat_minor": 4