This project implements a tumor segmentation model using the DICOM (Brain Tumor) dataset that was converted to NIFTI. It utilizes the SwinUNETR model for segmentation and provides functionality for inference, visualization, and volume calculation.
- Tumor segmentation using SwinUNETR model
- Sliding window inference for processing large 3D volumes
- Visualization of segmentation results and differences between two sets of inputs
- Volume calculation for different tumor regions
We provide Swin UNETR models which are pre-trained on BraTS21 dataset as in the following. The folds correspond to the data split in the json file.
| Name | Fold | Mean Dice | Feature Size | # params (M) | Download |
|---|---|---|---|---|---|
| Swin UNETR | 0 | 88.54 | 48 | 62.1 | model |
| Swin UNETR | 1 | 90.59 | 48 | 62.1 | model |
| Swin UNETR | 2 | 89.81 | 48 | 62.1 | model |
| Swin UNETR | 3 | 89.24 | 48 | 62.1 | model |
| Swin UNETR | 4 | 90.35 | 48 | 62.1 | model |
- Python
- PyTorch
- MONAI
- NumPy
- Nibabel
- Matplotlib
dicom2nifti pydicom
exact versions are given in requirements.txt file
-
orignal repository:
git clone https://github.com/yourusername/brats21-tumor-segmentation.git -
Install the required packages:
pip install -r requirements.txt -
Download the pre-trained model and place it in the project root directory as
model.pt.
-
Prepare your DICOM dataset files. The code expects the following file structure:
/content/zip/ ├── T1 ├── T2 ├── Flair └── ticefor comparison we need two sets of inputs like these
-
Update the
input_1andinput_2variables in themain()function with the paths to your input data. -
Run the script:
python main.py -
The script will perform inference on both sets of inputs, visualize the results, and save a comparison image as
slice_67_comparison.png -
Volume calculations and tumor growth/shrinkage information will be printed to the console.
- Modify the
unique_valueslist to focus on specific tumor regions (1: necrotic and non-enhancing tumor core, 2: peritumoral edema, 4: enhancing tumor). - Change the
roi_size,sw_batch_size, andoverlapparameters in themain()function to adjust the sliding window inference behavior.
The script generates:
- that which Slice has the highest Volume e.g 6.
- Console output with volume calculations and tumor growth/shrinkage information.
- A PNG image (
output_comparison.png) showing the segmentation results, differences, and highlighted regions for the specified slice.
This project uses the DICOM Brain Tumor dataset and the SwinUNETR model architecture.