mymesh.image.VoxelMesh#
- mymesh.image.VoxelMesh(img, h, threshold=None, threshold_direction=1, scalefactor=1, scaleorder=1, voxel_mode='elem', return_nodedata=False)[source]#
Generate voxel mesh of an image
- 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_direction (signed integer) – If threshold_direction is negative, values less than or equal to the threshold will be considered “inside” the mesh and the opposite if threshold_direction 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.
voxel_mode (str, optional) –
Determines whether image voxels are mapped to nodes or elements, by default “elem”.
”elem”: Each image voxel is considered to be a cube (or rectangular prism) element. An image with shape (l,m,n) will have l*m*n elements.
”node”: Each image voxel is considered to be a discrete point (node). An image with shape (l,m,n) will have l*m*n nodes.
return_nodedata (bool, optional) – Option to interpolate image data to the nodes rather than just the voxels (if voxel_mode=”elem”), by default False. This can add significant computational costs for large images.
- Returns:
voxel – Mesh object containing the voxel mesh. The image data are stored in voxel.ElemData[‘Image Data’] and optional voxel.NodeData[‘Image Data’]
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 = image.VoxelMesh(...)- Return type:
Examples
Create a voxel mesh of the full image, visualizing the image data stored in V.ElemData[‘Image Data’]:
img = mymesh.demo_image('bunny') voxelsize = (0.337891, 0.337891, 0.5) # mm V = image.VoxelMesh(img, voxelsize, scalefactor=0.25) V.Clip(normal=[0,1,0]).plot(scalars='Image Data', view='-x-z')
Create a thresholded voxel mesh:
img = mymesh.demo_image('bunny') voxelsize = (0.337891, 0.337891, 0.5) # mm V = image.VoxelMesh(img, voxelsize, threshold=100, scalefactor=0.25) V.plot(view='-x-z')