This repository contains tools for processing and handling MRI-based segmentation of ribs and sternum. The tools assist in creating training data for neural networks and reconstructing 3D segmentations from 2D predictions.
├── images/
│ ├── mri/ # Contains sample MRI images
│ └── segmentation/ # Contains sample segmentation masks
├── segmentation-helper/
│ ├── predictions/ # Contains nnU-Net predictions and metadata
│ ├── x_train/ # Contains extracted 2D slices for training
│ ├── y_train/ # Contains corresponding segmentation masks
│ ├── seg_reconstructor.py # Script for 3D volume reconstruction
│ ├── slice_creator.py # Script for creating 2D training slices
│ └── requirements.txt # Package dependencies
└── README.md
To install the required packages, navigate to the segmentation-helper directory and run:
cd segmentation-helper
pip install -r requirements.txt
This will install all necessary dependencies:
- numpy: For numerical computations and array operations
- SimpleITK: For medical image I/O and processing
- scipy: For scientific computing and image processing
- matplotlib: For visualization and plotting
- Pillow (PIL): For image processing and file I/O
The slice_creator.py
script provides an interactive tool for:
- Loading 3D MRI volumes and their segmentation masks
- Rotating volumes along specified rotation axes
- Interactive visualization and manipulation of slice positions
- Extracting and saving 2D slices with corresponding segmentation masks
- Automatic metadata generation for reconstruction
The seg_reconstructor.py
script enables:
- Reconstruction of 3D volumes from 2D slice predictions
- Preservation of original medical image properties (origin, spacing, direction)
- Application of morphological operations for cleaning and smoothing
- Place your MRI volume in the
images/mri/
directory - Place corresponding segmentation mask in
images/segmentation/
directory - Run the slice creator:
python slice_creator.py
The interactive interface allows you to:
- View the current slice and its position in the axial plane
- Drag the cyan rectangle to position the crop region
- Press Enter to save the current slice
- Press Space to skip the current slice
- Press Escape to end processing
Slices will be saved in:
x_train/
for MRI slicesy_train/
for segmentation masks- Metadata will be saved in
predictions/crop_metadata.json
After obtaining predictions for your 2D slices, use the reconstructor:
python seg_reconstructor.py
The script will:
- Load the 2D predictions
- Reconstruct them into a 3D volume
- Apply morphological cleaning
- Save the final volume in the specified medical image format
The slice creator provides an interactive interface for extracting 2D slices:
- Left: Current rotated slice view with adjustable crop region (cyan rectangle)
- Right: Axial view showing the slice plane positions
Example of a reconstructed segmentation:
- The repository includes sample data for demonstration purposes
- The tools are designed to work with the nnU-Net framework for segmentation
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.