Bone Segmentation using TotalSegmentor Threshold Slicer 5.6.2


I’ve been on the hunt for the best method to extract ribs from CT scans. It’s not a big deal if other internal parts get included in the process since my goal is to create 3D models of the bones, and study the rib curvatures. In fact, if the heart is also segmented, that is just a bonus. I’ve experimented with TotalSegmentor, but I have not been able to segment just the bones here, only the Vertebrae. I have also been guided by some tutorials on YouTube where they use tools like PaintBrush and WaterShed. All of these methods works, but I TotalSegmentor takes a lot of time (noGPU), and I would be very happy I could do as little manual annotation as possible.

I’ve seen discussions on this forum recommending the Threshold method. Yet, it seems I’m hitting a snag with my version of Slicer, as I can’t seem to apply this threshold (see attached image). It would be ideal if I could segment directly based on what the threshold outlines.

Any advice or workaround suggestions would be greatly appreciated!

Hans Martin


I solved this by writing a script that takes all the STLs from the folder with the search word rib, sternum and costal cartilage, and combines it into one. If any one is interested in such scripts see below.

import os
import numpy as np
from stl import mesh

def merge_stl_files(folder_path):
# Initialize an empty list to store mesh data
mesh_data =

# Iterate through files in the folder
for file_name in os.listdir(folder_path):
    if file_name.endswith('.stl') and ('rib' in file_name.lower() or 'sternum' in file_name.lower() or 'costal cartilage' in file_name.lower()):
        file_path = os.path.join(folder_path, file_name)
        print(f'Processing file: {file_name}')

        # Load the STL file
        part_mesh = mesh.Mesh.from_file(file_path)

        # Add mesh data to the list

# Concatenate mesh data to create merged mesh
merged_mesh_data = np.concatenate(mesh_data)

# Create a mesh object from the merged mesh data
merged_mesh = mesh.Mesh(merged_mesh_data)

# Output file path for the merged STL file
output_file = os.path.join(folder_path, 'Merged_Thoracic.stl')

# Write the merged mesh to the output STL file
print(f'Merged STL file saved as: {output_file}')

Folder path containing the STL files to merge

folder_path = ‘folderpath’

Call the function to merge STL files


1 Like