nighres.surface.levelset_to_mesh(levelset_image, connectivity='18/6', level=0.0, inclusive=True, save_data=False, overwrite=False, output_dir=None, file_name=None)[source]

Levelset to mesh

Creates a triangulated mesh from the distance to a levelset surface representation using a connectivity-consistent marching cube algorithm.

  • levelset_image (niimg) – Levelset image to be turned into a mesh
  • connectivity ({"6/18","6/26","18/6","26/6"}, optional) – Choice of digital connectivity to build the mesh (default is 18/6)
  • level (float, optional) – Value of the levelset function to use as isosurface (default is 0)
  • inclusive (bool, optional) – Whether voxels at the exact ‘level’ value are inside the isosurface (default is True)
  • save_data (bool, optional) – Save output data to file (default is False)
  • overwrite (bool, optional) – Overwrite existing results (default is False)
  • output_dir (str, optional) – Path to desired output directory, will be created if it doesn’t exist
  • file_name (str, optional) – Desired base name for output files with file extension (suffixes will be added)

Dictionary collecting outputs under the following keys (suffix of output files in brackets)

  • result (mesh): Surface mesh dictionary of “points” and “faces” (_l2m-mesh)

Return type:



Ported from original Java module by Pierre-Louis Bazin. Original algorithm from [1] and adapted from [2].


[1]Han et al (2003). A Topology Preserving Level Set Method for Geometric Deformable Models doi:
[2]Lucas et al (2010). The Java Image Science Toolkit (JIST) for Rapid Prototyping and Publishing of Neuroimaging Software doi:

Examples using nighres.surface.levelset_to_mesh