{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Convert images to meshes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from vedo import Picture, settings, printc, show\n",
"from vedo.applications import SplinePlotter\n",
"\n",
"settings.default_backend = \"vtk\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
" \n",
" | \n",
" \n",
"vedo.picture.Picture
(../data/sox9_exp.jpg) \n",
"\n",
" shape | (876, 720) | \n",
" in memory size | 616 KB | \n",
" point data array | JPEGImage | \n",
"\n",
" intensity range | (42.0, 255.0) | \n",
" level / window | 127.5 / 255.0 | \n",
" \n",
" |
"
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pic = Picture(\"../data/sox9_exp.jpg\").bw()\n",
"pic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Select the contour of the limb. \n",
"# Click q when done.\n",
"plt = SplinePlotter(pic)\n",
"plt.show(mode=\"image\", zoom='tight')\n",
"outline = plt.line\n",
"plt.close()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[7m\u001b[1m\u001b[32mCutting with outline... (may take a fews secs)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
" \n",
"vedo.mesh.Mesh
(../data/sox9_exp.jpg) \n",
"\n",
" bounds (x/y/z) | 164.3 ... 814.7 73.01 ... 632.7 0 ... 0 | \n",
" center of mass | (490, 365, 0) | \n",
" average size | 201.149 | \n",
" nr. points / faces | 276428 / 548406 | \n",
"\n",
"\n",
" \n",
" |
"
],
"text/plain": [
""
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"printc(\"Cutting with outline... (may take a fews secs)\", invert=True, c='g')\n",
"msh = pic.tomesh().cmap(\"viridis_r\")\n",
"cut_msh = msh.clone().cut_with_point_loop(outline)\n",
"cut_msh"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" | \n",
" \n",
"vedo.mesh.Mesh
(../data/sox9_exp.jpg) \n",
"\n",
" bounds (x/y/z) | 164.3 ... 814.7 73.01 ... 632.7 0 ... 0 | \n",
" center of mass | (490, 365, 0) | \n",
" average size | 201.149 | \n",
" nr. points / faces | 276428 / 548406 | \n",
" point data array | RGBA | \n",
"\n",
" \n",
" |
"
],
"text/plain": [
""
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# interpolate the original data by looking at the 3 closest points\n",
"cut_msh.interpolate_data_from(msh, n=3)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"show(cut_msh, outline, axes=1).close()"
]
}
],
"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.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}