Skip to main content

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) or cuboid (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.

  1. Fork the repository
  2. Create your branch (git checkout -b feature/AmazingFeature)
  3. Add your changes to the branch
  4. Commit your changes (git commit -m 'Add some AmazingFeature')
  5. Push to the branch (git push origin feature/AmazingFeature)
  6. 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

neuroslice-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuroslice-1.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file neuroslice-1.0.0.tar.gz.

File metadata

  • Download URL: neuroslice-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for neuroslice-1.0.0.tar.gz
Algorithm Hash digest
SHA256 679804a21dc938c8681beab60b2f3113f7fd218282a3bf7cfc79d5eedee3b4b5
MD5 4c01915f9dfc6e0290f4eca44bd5d01c
BLAKE2b-256 de395b52cef430faa0cb3c89b6d7df574dd09c02bf5014d5cf39194bd7fb241c

See more details on using hashes here.

File details

Details for the file neuroslice-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: neuroslice-1.0.0-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.8.18

File hashes

Hashes for neuroslice-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e1c13a22287113b46db06d9d4d9c6214b91b62b0cc02aa13b3319d88dacd2ac
MD5 3ce33b150850c74ba84904b75513658a
BLAKE2b-256 c55efe85c03b34b02e73b0f36c9e3c56a3d81f3dde84340d81730787ec0adde2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page