mymesh.contour.MarchingSquaresImage#

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

Marching squares algorithm applied to 2D image data.

Image data is assumed to be pixel data and will be interpolated to vertices to get the corners of each square.

Parameters:
  • I (np.ndarray) – Image array (2D) of grayscale data

  • h (float or tuple, optional) – Element (pixel) size. Can be specified as a single value for isotropic pixel sizes or a tuple of two values, by default 1

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

  • z (float, optional) – z coordinate that will be used for all nodes, 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 ‘edge’ for a line mesh of the boundary or ‘triangle’ for a filled triangular mesh, by default ‘triangle’

  • 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