mymesh.contour.MarchingSquaresImage#
- mymesh.contour.MarchingSquaresImage(I, h=1, threshold=0, z=0, interpolation='linear', Type='surf', VertexValues=False, flip=False, mixed_elements=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
Type (str, optional) – Determines whether to generate a surface mesh (‘surf’) or volume mesh (‘vol’), by default ‘surf’
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’mixed_elements (bool, optional) – If True and Type=’surf’, the generated mesh will have mixed element types (triangles/quadrilateral otherwise a single element type (triangles), by default False.
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