Slice-wise brain tumor detection and 3D mask reconstruction from MRI
Project description
Neuroslice
A Python package for brain tumor segmentation using YOLO models on MRI FLAIR data.
Table of Contents
Description
Neuroslice provides automated brain tumor bounding box detection using pre-trained YOLO models. It uses FLAIR images to segment slice wise the image, though an option to create a cuboid is available. The package supports three slice orientations (coronal, sagittal, and axial). Models are automatically downloaded from Hugging Face when first used.
Installation
You can install Neuroslice using pip:
pip install neuroslice
For development installation:
git clone https://github.com/anamatoso/neuroslice.git
cd neuroslice
pip install -e .
Usage
Command Line Interface
Basic usage with default settings (coronal direction, union mode):
neuroslice input.nii.gz output_mask.nii.gz
Specify slice direction and processing mode:
neuroslice input.nii.gz output_mask.nii.gz --direction 2 --mode cuboid --verbose
Arguments:
Mandatory:
input: Path to input NIfTI file (.nii or .nii.gz)output: Path to output mask NIfTI file
Optional:
--direction: Slice direction - 0 (sagittal), 1 (coronal, default), 2 (axial)--mode: Processing mode -union(default) orcuboid(bounding box)--verbose: Print details
Python API
Generate a tumor mask:
from neuroslice import predict_mask
import nibabel as nib
# Generate mask from NIfTI file
mask = predict_mask("input.nii.gz", 1, verbose=True)
# Save the mask
nifti = nib.load("input.nii.gz")
output = nib.Nifti1Image(mask.astype("uint8"), nifti.affine, nifti.header)
nib.save(output, "output_mask.nii.gz")
Convert mask to bounding cuboid:
from neuroslice import mask2cuboid_array, mask2cuboid_nifti
# From array
cuboid_mask = mask2cuboid_array(mask)
# From NIfTI file
mask2cuboid_nifti("mask.nii.gz", "cuboid_mask.nii.gz")
Combine multiple masks:
from neuroslice import unite_masks_array, unite_masks_nifti
# Combine arrays
combined = unite_masks_array(mask1, mask2, mask3, method="union")
# Combine NIfTI files
unite_masks_nifti(
["mask1.nii.gz", "mask2.nii.gz", "mask3.nii.gz"],
"combined_mask.nii.gz",
method="cuboid"
)
Advanced usage with direct predict function:
from neuroslice import predict
from ultralytics import YOLO
import nibabel as nib
# Load your data
nifti = nib.load("input.nii.gz")
data = nifti.get_fdata()
# Generate mask with custom axis
mask = predict(data, axis=0, verbose=True)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your branch (
git checkout -b feature/AmazingFeature) - Add your changes to the branch
- Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Citation
If you use Neuroslice in your research, please cite:
TBD
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neuroslice-0.0.3.tar.gz.
File metadata
- Download URL: neuroslice-0.0.3.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc1303009c55ebcaa2aef254558a4e70a070e2c7ecbb743feeec89b341ca4a99
|
|
| MD5 |
59e0137c455c3654d150229715a6d083
|
|
| BLAKE2b-256 |
346907a47753d6cf0628ced897fd9490d9bdcfe339b4eccc3e190b4c50e2ad4e
|
File details
Details for the file neuroslice-0.0.3-py3-none-any.whl.
File metadata
- Download URL: neuroslice-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
088416a7c81d523078cb94a76733f2ab8d2a708d9ab4a5c04236d24e27427181
|
|
| MD5 |
c4604ecf2a8bc9478e8fd74d8015a8eb
|
|
| BLAKE2b-256 |
d22bd53fd7786c639a4fa9e758178582fc8c869d0024e0d4bde23efb34b723b0
|