Marching cubes#

Marching cubes was developed in 1987 and was originally designed for efficient visualization of medical image data. In short, a cube-shaped neighborhood is moved through the image and the and the corners of the cube are classified as either inside or outside the object of interest. The cube is then triangulated based on the classification of the corners. This is repeated for all cubes in the image. The result is a triangulated surface that approximates the object of interest.

Among other algorithms, marching cubes presents a key method to transition from volumetric data to surface space. It is implemented, for instance, in scikit-image.


Before running this notebook, make sure to install the following dependencies:

mamba install vedo napari-process-points-and-surfaces
import napari_process_points_and_surfaces as nppas
import napari_segment_blobs_and_things_with_membranes as nsbatwm
from skimage import measure, data

import vedo
import napari
vedo.settings.default_backend= 'vtk'
viewer = napari.Viewer(ndisplay=3)


We first obtain a segmentation of some data to get started. We continue where we left of in one of the previous notebooks about voronoi-otsu thresholding.

raw_data = data.cells3d()
outline_sigma = 2
nuclei_sigma = 10
nuclei = raw_data[:, 1]
segmentation = nsbatwm.voronoi_otsu_labeling(nuclei, spot_sigma=nuclei_sigma, outline_sigma=outline_sigma)
viewer.add_image(nuclei, name='nuclei', colormap='magenta', blending='additive')