{
"cells": [
{
"cell_type": "markdown",
"id": "ff11395c-5b0c-4df8-8b20-a5ab712d31ff",
"metadata": {},
"source": [
"# Speichern und Laden von Oberfl\u00e4chen\n",
"In diesem Notebook werden wir eine Oberfl\u00e4che auf der Festplatte speichern und von dort wieder laden, unter Verwendung von [vedo](https://vedo.embl.es/).\n",
"\n",
"Siehe auch\n",
"* https://vedo.embl.es/docs/vedo/io.html#write\n",
"* https://vedo.embl.es/docs/vedo/io.html#load"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a43114eb-755f-485d-b602-4d0b6f5330da",
"metadata": {},
"outputs": [],
"source": [
"import napari_process_points_and_surfaces as nppas\n",
"import vedo\n",
"\n",
"from branchoid import branchoid"
]
},
{
"cell_type": "markdown",
"id": "526101a6-9bec-461c-9f27-140252b1ee0b",
"metadata": {},
"source": [
"Ausgangspunkt ist wieder die Oberfl\u00e4che des simulierten Branchoids."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0bec9a3c-4553-40e9-b51e-3a4d666cb855",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"nppas.SurfaceTuple \n",
"\n",
"origin (z/y/x) | [0. 0. 0.] | \n",
"center of mass(z/y/x) | 50.000,46.575,42.589 | \n",
"scale(z/y/x) | 1.000,1.000,1.000 | \n",
"bounds (z/y/x) | 25.500...74.500 2.500...88.500 2.500...83.500 | \n",
"average size | 31.277 | \n",
"number of vertices | 19040 | \n",
"number of faces | 38076 | \n",
"\n",
" \n",
"\n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"(array([[25.5, 44. , 47. ],\n",
" [26. , 43.5, 47. ],\n",
" [26. , 44. , 46.5],\n",
" ...,\n",
" [74.5, 56. , 51. ],\n",
" [74.5, 56. , 52. ],\n",
" [74.5, 56. , 53. ]], dtype=float32),\n",
" array([[ 2, 1, 0],\n",
" [ 4, 3, 0],\n",
" [ 4, 0, 1],\n",
" ...,\n",
" [19038, 18870, 18872],\n",
" [19038, 18872, 19039],\n",
" [19039, 18872, 18852]], dtype=int64))"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"binary_image = branchoid()\n",
"surface = nppas.all_labels_to_surface(binary_image)\n",
"surface"
]
},
{
"cell_type": "markdown",
"id": "9a7a1d1c-3e06-4015-bf11-fcd26cd09586",
"metadata": {},
"source": [
"## Speichern von Oberfl\u00e4chen auf der Festplatte\n",
"Die [vedo](https://vedo.embl.es/) Bibliothek stellt Funktionen zum Speichern und Laden von Oberfl\u00e4chennetzen bereit. Um sie von/zu napari-kompatiblen Oberfl\u00e4chen-Tupeln zu konvertieren, verwenden wir [napari-process-points-and-surfaces (nppas)](https://github.com/haesleinhuepf/napari-process-points-and-surfaces)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2c40840a-d892-4071-9286-752924170582",
"metadata": {},
"outputs": [],
"source": [
"mesh = nppas.to_vedo_mesh(surface)\n",
"\n",
"filename = \"../../data/branchoid.ply\"\n",
"\n",
"_ = vedo.write(mesh, filename)"
]
},
{
"cell_type": "markdown",
"id": "8563f75b-3320-4151-b29f-b54caf5418aa",
"metadata": {},
"source": [
"## Laden von Netzen von der Festplatte"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "827dffde-feb0-4b74-8666-b8dee735e379",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
" \n",
"vedo.mesh.Mesh
(../../data/branchoid.ply) \n",
"\n",
" bounds (x/y/z) | 25.50 ... 74.50 2.500 ... 88.50 2.500 ... 83.50 | \n",
" center of mass | (50.0, 46.6, 42.6) | \n",
" average size | 31.277 | \n",
" nr. points / faces | 19040 / 38076 | \n",
"\n",
"\n",
" \n",
" |
"
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_mesh = vedo.load(filename)\n",
"new_mesh"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a35e74e4-113d-41f5-9bde-25a7875d4a0a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
"\n",
"nppas.SurfaceTuple \n",
"\n",
"origin (z/y/x) | [0. 0. 0.] | \n",
"center of mass(z/y/x) | 50.000,46.575,42.589 | \n",
"scale(z/y/x) | 1.000,1.000,1.000 | \n",
"bounds (z/y/x) | 25.500...74.500 2.500...88.500 2.500...83.500 | \n",
"average size | 31.277 | \n",
"number of vertices | 19040 | \n",
"number of faces | 38076 | \n",
"\n",
" \n",
"\n",
" | \n",
"
\n",
"
"
],
"text/plain": [
"(array([[25.5, 44. , 47. ],\n",
" [26. , 43.5, 47. ],\n",
" [26. , 44. , 46.5],\n",
" ...,\n",
" [74.5, 56. , 51. ],\n",
" [74.5, 56. , 52. ],\n",
" [74.5, 56. , 53. ]], dtype=float32),\n",
" array([[ 2, 1, 0],\n",
" [ 4, 3, 0],\n",
" [ 4, 0, 1],\n",
" ...,\n",
" [19038, 18870, 18872],\n",
" [19038, 18872, 19039],\n",
" [19039, 18872, 18852]], dtype=int64))"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_surface = nppas.to_napari_surface_data(new_mesh)\n",
"new_surface"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5cebe5c5-06b8-423e-8632-ac2a3297967a",
"metadata": {},
"outputs": [],
"source": []
}
],
"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",
"version": "3.9.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}