mymesh.converter.im2voxel#
- mymesh.converter.im2voxel(img, voxelsize, scalefactor=1, scaleorder=1, return_gradient=False, gaussian_sigma=1, threshold=None, crop=None, threshold_direction=1, voxel_mode='elem', return_nodedata=False)[source]#
Convert 3D image data to a cubic mesh. Each voxel will be represented by an element.
- Parameters:
img (str or np.ndarray) – If a str, should be the directory to an image stack of tiff or dicom files. If an array, shoud be a 3D array of image data.
voxelsize (float, or tuple) – Size of voxel (based on image resolution). If a tuple, should be specified as (hx,hy,hz)
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.
threshold (float, optional) – Voxel intensity threshold, by default None. If given, elements with all nodes less than threshold will be discarded.
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) – If True and if
voxel_mode = "elem", node data will be averaged from adjacent voxels.
- Returns:
VoxelCoords (list) – Node coordinates for the voxel mesh
VoxelConn (list) – Node connectivity for the voxel mesh
VoxelData (numpy.ndarray) – Image intensity data for each voxel. Returned if
voxel_mode = "elem"NodeData (numpy.ndarray) – Image intensity data for each node, averaged from connected voxels. Returned if
voxel_mode = "node"orreturn_nodedata = True.