Simple python code that transfers a single segmented nii.gz file to a list of stl files based on the labels inside.
Your output segmented nii.gz file from other segmentation algorithms may contain series of identical labels, such as 1,2,4,5. If you would like to view or save them seperately without using expensive software, or you want to integrate this function into your own code, then the code will be helpful. It could transfer this single nii.gz file into series of .stl files using simpleITK and vtk to create the mesh and save these individual files in your folder.
This code can be used in many medical imaging situations as a final step of processing output that be read by clients. Labels do not require to be continuous, but need to be numbers (int, float...)
T7 | T10 | L5 |
It will also smooth the surface (parameters can be changed) for the outputs
No smooth | Smoothed |
cd YOUR_RESULT_FOLDER
python nii_2_mesh_v3.py
Output the corresponding .json file with all the coordinates for each label and the bounding box may be helpful.