This repository contains a comprehensive pipeline for reconstructing 3D volumetric rib models from biplanar medical segmentations. The pipeline processes coronal and sagittal view segmentations to extract 2D midlines, create parametric curve representations, reconstruct 3D midlines, and generate detailed volumetric meshes.
├── segmentations/
│ ├── coronal/ # Contains coronal view segmentation files
│ └── sagittal/ # Contains sagittal view segmentation files
├── src/
│ ├── process_ribs.py # Main execution script
│ ├── rib_midline_extractor.py # 2D midline extraction and 3D reconstruction
│ ├── rib_midline_parametrization.py # Parametric curve generation
│ ├── rib_volumetric_reconstructor.py # Volumetric modeling and mesh generation
│ └── rib_visualizer.py # Comprehensive visualization methods
├── LICENSE
├── README.md
└── requirements.txt # Package dependencies
To install the required packages, run:
pip install -r requirements.txtThis will install all necessary dependencies:
- numpy: For numerical computations and array operations
- scipy: For scientific computing and spline interpolation
- matplotlib: For visualization and plotting
- nibabel: For loading NIfTI medical image files
- scikit-image: For image processing and morphological operations
- pyvista: For advanced 3D visualization (optional but recommended)
The rib_midline_extractor.py module provides:
- Loading and preprocessing of biplanar NIfTI segmentations
- Automatic rotation and orientation correction
- Morphological operations for improved connectivity
- Skeletonization to extract centerlines
- 3D reconstruction using orthogonal projection geometry
The rib_midline_parametrization.py module enables:
- Conversion of skeletal midlines to ordered point sequences
- Spline-based parametric curve fitting with adaptive smoothing
- Robust handling of sparse or noisy midline data
- Consistent parameterization for biplanar correspondence
The rib_volumetric_reconstructor.py module supports:
- Cross-sectional dimension measurement from biplanar views
- Anatomically oriented elliptical cross-section generation
- Triangular mesh creation with anterior tapering
- Comprehensive volumetric model generation
The rib_visualizer.py module includes:
- 2D midline visualization on segmentation backgrounds
- Parametric curve visualization with control points
- Interactive 3D midline and mesh visualization
- Cross-sectional measurement methodology display
-
Update the file paths in
process_ribs.pyto point to your segmentation data:coronal_seg_path = "path/to/your/coronal_segmentation.nii.gz" sagittal_seg_path = "path/to/your/sagittal_segmentation.nii.gz"
-
Run the complete pipeline:
python process_ribs.py
The pipeline will:
- Extract 2D midlines from biplanar segmentations
- Create parametric curve representations
- Reconstruct 3D midlines using orthogonal geometry
- Generate volumetric models with cross-sections and meshes
- Create comprehensive visualizations
- The pipeline expects NIfTI format (.nii.gz) binary segmentations
- Input segmentations should have matching rib indices between coronal and sagittal views
- PyVista is optional but recommended for 3D visualizations
- The pipeline assumes orthogonal biplanar geometry
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.