mymesh.image.SurfaceMesh#

mymesh.image.SurfaceMesh(img, h, threshold=None, threshold_direction=1, scalefactor=1, scaleorder=1, method='mc', interpolation='linear')[source]#

Generate a surface mesh of an image function

Parameters:
  • img (str or np.ndarray) – Image array or file path to an image

  • h (scalar, tuple) – Voxel size of the image. Can be specified as a single scalar value, or a three element tuple (or array_like). If a tuple, entries should correspond to (hx, hy, hz).

  • threshold (scalar) – Isovalue threshold to use for keeping/removing elements, by default 0.

  • threshold_dir (signed integer) – If threshold_dir is negative (default), values less than or equal to the threshold will be considered “inside” the mesh and the opposite if threshold_dir is positive, by default 1.

  • scalefactor (float, optional) – Scale factor for resampling the image. If greater than 1, there will be more than 1 elements per voxel. If less than 1, will coarsen the image, by default 1.

  • scaleorder (int, optional) – Interpolation order for scaling the image (see scipy.ndimage.zoom), by default 1. Must be 0-5.

  • method (str, optional) –

    Surface triangulation method, by default ‘mc’. ‘mc’ : Marching cubes (see contour.MarchingCubesImage) (default)

    ’mc33’ : Marching cubes 33 (see contour.MarchingCubes)

    ’mt’ : Marching tetrahedra (see contour.MarchingTetrahedra)

  • interpolation (str, optional) – Method of interpolation used for placing the vertices on the approximated isosurface. This can be ‘midpoint’, ‘linear’, or ‘cubic’, by default ‘linear’. If ‘cubic’ is selected, method is overridden to be ‘mc’.

Returns:

surface – Mesh object containing the surface mesh.

Note

Due to the ability to unpack the mesh object to NodeCoords and NodeConn, the NodeCoords and NodeConn array can be returned directly (instead of the mesh object) by running: NodeCoords, NodeConn = implicit.SurfaceMesh(...)

Return type:

mymesh.mesh

Examples

surface = implicit.SurfaceMesh(implicit.gyroid, [0,1,0,1,0,1], 0.05)
surface.plot(bgcolor='w')
../../_images/mymesh-image-SurfaceMesh-1.png