nifti_to_mesh
tit.tools.nifti_to_mesh ¶
Convert a NIfTI segmentation/mask to a surface mesh.
Applies marching cubes to a binary mask derived from a NIfTI volume
and writes the resulting surface as binary STL or Gmsh ASCII .msh.
Usage¶
$ python -m tit.tools.nifti_to_mesh segmentation.nii.gz -o thalamus.stl $ python -m tit.tools.nifti_to_mesh mask.nii.gz --clean --output mesh.msh
See Also¶
tit.tools.mesh2nii : Inverse operation (mesh to NIfTI). tit.tools.extract_labels : Pre-filter labels before meshing.
remove_small_components ¶
Remove connected components smaller than threshold * largest component.
Parameters¶
mask : ndarray Binary mask array threshold : float Minimum size threshold as fraction of largest component (0-1)
Returns¶
ndarray Cleaned binary mask
Source code in tit/tools/nifti_to_mesh.py
nifti_to_mesh ¶
Convert a NIfTI segmentation/mask to a surface mesh.
Parameters¶
input_file : str or Path Path to input NIfTI file output_file : str or Path, optional Path to output mesh file (.stl or .msh). If None, defaults to input_file with .stl extension clean_components : bool Whether to remove small disconnected components clean_threshold : float Minimum size threshold for component removal (as fraction of largest component)
Returns¶
dict Dictionary with mesh statistics: {'vertices': int, 'faces': int, 'output_file': str}
Source code in tit/tools/nifti_to_mesh.py
save_stl ¶
Save mesh as binary STL format using numpy-stl.
Source code in tit/tools/nifti_to_mesh.py
save_gmsh ¶
Save mesh as Gmsh .msh format (v2.2 ASCII).
Source code in tit/tools/nifti_to_mesh.py
main ¶
Command-line entry point for NIfTI-to-mesh conversion.