mymesh.contour.MarchingCubesImage#

mymesh.contour.MarchingCubesImage(I, h=1, threshold=0, interpolation='linear', method='original', VertexValues=False, edgemode='constant', flip=False, cleanup=True)[source]#

Marching cubes algorithm [LC87] applied to 3D image data.

Parameters:
  • I (np.ndarray) – Image array (3D) of grayscale data. The (0,1,2) axes of the image should correspond to the (z,y,x) axes, respectively.

  • h (float or tuple, optional) – Element (pixel) size. Can be specified as a single value for isotropic pixel sizes or a tuple of three values, by default 1. If a tuple, entries should correspond to (hx, hy, hz).

  • threshold (int, optional) – Isosurface level that defines the boundary, by default 0

  • interpolation (str, optional) –

    Interpolation to interpolate the position of the new nodes along the edges of the input mesh, by default ‘linear’.

    ’midpoint’ - No interpolation is performed, new nodes are placed at the midpoint of edges

    ’linear’ - Bilinear interpolation is performed between adjacent nodes on the input mesh

    ’cubic’ - Bicubic interpolation is performed between adjacent nodes on the input mesh

  • method (str, optional) – Mesh generation method, either ‘original’ for the original marching cubes algorithm or ‘33’ for the marching cubes 33 algorithm [Che95].

  • VertexValues (bool, optional) – If True, the values in the image array are treated as the vertices of the cubes, otherwise, they are treated as voxel values and vertices are obtained through interpolation, by default, False.

  • flip (bool, optional) – Flip the interior/exterior of the mesh, by default False. By default, values less than the threshold are assumed to be the “inside” of the mesh. If the inside is denoted by values greater than the threshold, set flip=True.

  • edgemode (str, optional) – For interpolation=’cubic’, edgemode specifies how to handle boundary nodes. The image matrix will be padded using np.pad(I, 1, mode=edgemode), by default ‘constant’

  • cleanup (bool, optional) – Determines whether or not to perform mesh cleanup, removing degenerate elements and duplicate nodes, by default True

Returns:

  • NewCoords (np.ndarray) – Numpy array of node coordinates for the contour mesh

  • NewConn (list) – List of node connectivities