From surface data to image data#

In this notebook we will turn surfaces into binary and label images.

import napari_process_points_and_surfaces as nppas
import vedo
mesh = vedo.load("../../data/branchoid.ply")
surface = nppas.to_napari_surface_data(mesh)

surface
nppas.SurfaceTuple
origin (z/y/x)[0. 0. 0.]
center of mass(z/y/x)50.000,46.575,42.589
scale(z/y/x)1.000,1.000,1.000
bounds (z/y/x)25.500...74.500
2.500...88.500
2.500...83.500
average size31.277
number of vertices19040
number of faces38076

Binary volumes#

A common task is to fill a volume to create a binary image stack.

binary_image = nppas.surface_to_binary_volume(surface)
binary_image
shape(49, 86, 81)
dtypeint32
size1.3 MB
min0
max1

Labeled surface voxels#

We can also sample points from the surface and turn these points into a label image.

point_cloud = nppas.sample_points_from_surface(surface, distance_fraction=0.01)
point_cloud
array([[26. , 44. , 46.5],
       [26. , 43.5, 48. ],
       [26. , 43.5, 50. ],
       ...,
       [74.5, 55. , 52. ],
       [74.5, 56. , 49. ],
       [74.5, 56. , 51. ]], dtype=float32)
point_labels = nppas.points_to_labels(point_cloud)
point_labels
shape(76, 90, 85)
dtypeint32
size2.2 MB
min0
max5167
point_labels[50]
shape(90, 85)
dtypeint32
size29.9 kB
min0
max2678

These labels can also be turned into points again.

centroids = nppas.labels_to_centroids(point_labels)
centroids[:10]
[(26.0, 44.0, 47.0),
 (26.0, 44.0, 48.0),
 (26.0, 44.0, 50.0),
 (26.0, 44.0, 52.0),
 (26.0, 44.0, 54.0),
 (26.0, 45.0, 46.0),
 (26.0, 45.0, 48.0),
 (26.0, 45.0, 50.0),
 (26.0, 45.0, 52.0),
 (26.0, 45.0, 55.0)]