First implementation
This commit is contained in:
100
notebooks/annotation_segmentation.ipynb
Normal file
100
notebooks/annotation_segmentation.ipynb
Normal file
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fe0521db",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pathlib import Path\n",
|
||||
"import json\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from PIL import Image\n",
|
||||
"from IPython.display import display, Image as IPImage"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c6d7ebbf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"out_dir = Path(\"../data/annotation_results/\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "75efc15a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def show_result(folder):\n",
|
||||
" folder = Path(folder)\n",
|
||||
"\n",
|
||||
" with open(folder / \"metadata.json\") as f:\n",
|
||||
" metadata = json.load(f)\n",
|
||||
"\n",
|
||||
" frame = np.array(Image.open(folder / \"frame.png\"))\n",
|
||||
" mask = np.array(Image.open(folder / \"mask_vis.png\"))\n",
|
||||
" overlay = np.array(Image.open(folder / \"overlay.png\"))\n",
|
||||
"\n",
|
||||
" title = \" | \".join(f\"{k}: {v}\" for k, v in metadata.items())\n",
|
||||
" fig, axs = plt.subplots(1, 3, figsize=(15, 5))\n",
|
||||
" axs[0].imshow(frame)\n",
|
||||
" axs[0].set_title(\"Frame\")\n",
|
||||
" axs[0].axis(\"off\")\n",
|
||||
" axs[1].imshow(mask, cmap=\"gray\")\n",
|
||||
" axs[1].set_title(\"Mask\")\n",
|
||||
" axs[1].axis(\"off\")\n",
|
||||
" axs[2].imshow(overlay)\n",
|
||||
" axs[2].set_title(\"Overlay\")\n",
|
||||
" axs[2].axis(\"off\")\n",
|
||||
" plt.suptitle(f\"{folder.name}\\n{title}\", fontsize=9)\n",
|
||||
" plt.tight_layout()\n",
|
||||
" plt.show()\n",
|
||||
"\n",
|
||||
" for gif_name in [\"video_original_lowres.gif\", \"video_overlay_lowres.gif\"]:\n",
|
||||
" gif_path = folder / gif_name\n",
|
||||
" if gif_path.exists():\n",
|
||||
" display(IPImage(filename=str(gif_path)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "02ff1ae9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for folder in sorted(out_dir.iterdir()):\n",
|
||||
" if folder.is_dir() and (folder / \"metadata.json\").exists():\n",
|
||||
" show_result(folder)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "river-annotation-tool",
|
||||
"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",
|
||||
"version": "3.12.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user