Creating surfaces#
In this notebook we create a surface (mesh) from a simulated 3D binary image dataset.
import napari_process_points_and_surfaces as nppas
import pyclesperanto_prototype as cle
import vedo
from branchoid import branchoid
binary_image = branchoid()
binary_image
|
Generating surfaces#
We first generate a surface from the binary image. In this case, we take all non-zero labeled pixels and turn them into a surface.
surface = nppas.all_labels_to_surface(binary_image)
The resulting object is visualized in Jupyter notebooks like this:
surface
nppas.SurfaceTuple
|
Technically, it is a tuple.
isinstance(surface, tuple)
True
The tuple contains vertices and faces.
vertices, faces = surface
Vertices are lists of lists of Z/Y/X coordinates in 3D space.
vertices
array([[25.5, 44. , 47. ],
[26. , 43.5, 47. ],
[26. , 44. , 46.5],
...,
[74.5, 56. , 51. ],
[74.5, 56. , 52. ],
[74.5, 56. , 53. ]], dtype=float32)
Faces are lists of lists of indices. Every triangle has three point coordinates indexed like this:
faces
array([[ 2, 1, 0],
[ 4, 3, 0],
[ 4, 0, 1],
...,
[19038, 18870, 18872],
[19038, 18872, 19039],
[19039, 18872, 18852]], dtype=int64)
Surfaces from individual labels#
If we have a label image as starting point, we can also turn individual objects into surfaces.
labels = cle.voronoi_otsu_labeling(binary_image, spot_sigma=6)
labels
cle._ image
|
nppas.largest_label_to_surface(labels)
nppas.SurfaceTuple
|
nppas.label_to_surface(labels, label_id=1)
nppas.SurfaceTuple
|
nppas.label_to_surface(labels, label_id=2)
nppas.SurfaceTuple
|
Creating surfaces using vedo#
Vedo also offers functions for creating surfaces such as iso_surface()
.
volume = vedo.Volume(binary_image)
iso_surface = volume.isosurface()
iso_surface
vedo.mesh.Mesh
|
The resulting data structure is a vedo Mesh. You can access its points and faces as well.
iso_surface.points()
array([[49. , 11. , 2.3333333],
[50. , 11. , 2.3333333],
[51. , 11. , 2.3333333],
...,
[50. , 55. , 83.666664 ],
[51. , 55. , 83.666664 ],
[52. , 55. , 83.666664 ]], dtype=float32)
iso_surface.faces()[:10]
[[0, 92, 104],
[0, 1, 93],
[92, 0, 93],
[1, 2, 94],
[93, 1, 94],
[94, 2, 105],
[3, 106, 118],
[3, 4, 107],
[106, 3, 107],
[104, 107, 4]]
Exercise#
Load the skimage.data.cells3d
dataset, extract the second channel and create a surface mesh from the nuclei.