Convert images to meshes#

from vedo import Picture, settings, printc, show
from vedo.applications import SplinePlotter

settings.default_backend = "vtk"
pic = Picture("../data/sox9_exp.jpg").bw()
pic

vedo.picture.Picture
(../data/sox9_exp.jpg)
shape (876, 720)
in memory size 616 KB
point data array JPEGImage
intensity range (42.0, 255.0)
level / window 127.5 / 255.0
# Select the contour of the limb. 
# Click q when done.
plt = SplinePlotter(pic)
plt.show(mode="image", zoom='tight')
outline = plt.line
plt.close()
printc("Cutting with outline... (may take a fews secs)", invert=True, c='g')
msh = pic.tomesh().cmap("viridis_r")
cut_msh = msh.clone().cut_with_point_loop(outline)
cut_msh
Cutting with outline... (may take a fews secs)

vedo.mesh.Mesh
(../data/sox9_exp.jpg)
bounds
(x/y/z)
164.3 ... 814.7
73.01 ... 632.7
0 ... 0
center of mass (490, 365, 0)
average size 201.149
nr. points / faces 276428 / 548406
# interpolate the original data by looking at the 3 closest points
cut_msh.interpolate_data_from(msh, n=3)

vedo.mesh.Mesh
(../data/sox9_exp.jpg)
bounds
(x/y/z)
164.3 ... 814.7
73.01 ... 632.7
0 ... 0
center of mass (490, 365, 0)
average size 201.149
nr. points / faces 276428 / 548406
point data array RGBA
show(cut_msh, outline, axes=1).close()