创建表面#
在这个笔记本中,我们从模拟的3D二值图像数据集创建一个表面(网格)。
import napari_process_points_and_surfaces as nppas
import pyclesperanto_prototype as cle
import vedo
from branchoid import branchoid
binary_image = branchoid()
binary_image
|
|
|
生成表面#
我们首先从二值图像生成一个表面。在这种情况下,我们将所有非零标记的像素转换为表面。
surface = nppas.all_labels_to_surface(binary_image)
在Jupyter笔记本中,结果对象的可视化如下:
surface
|
|
nppas.SurfaceTuple
|
从技术角度来看,它是一个元组。
isinstance(surface, tuple)
True
这个元组包含顶点和面。
vertices, faces = surface
顶点是3D空间中Z/Y/X坐标的列表的列表。
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
array([[ 2, 1, 0],
[ 4, 3, 0],
[ 4, 0, 1],
...,
[19038, 18870, 18872],
[19038, 18872, 19039],
[19039, 18872, 18852]], dtype=int64)
从单个标签创建表面#
如果我们以标签图像为起点,我们也可以将单个对象转换为表面。
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
|
使用vedo创建表面#
Vedo还提供了创建表面的函数,如iso_surface()。
volume = vedo.Volume(binary_image)
iso_surface = volume.isosurface()
iso_surface
|
|
vedo.mesh.Mesh
|
生成的数据结构是一个vedo网格。你也可以访问它的点和面。
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]]
练习#
加载skimage.data.cells3d数据集,提取第二个通道,并从细胞核创建一个表面网格。