Skip to main content

Slice-wise brain tumor detection and 3D mask reconstruction from MRI

Project description

Neuroslice

Python 3.10+

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 afterwards create a cuboid is available. The package supports three slice orientations (coronal, sagittal, and axial) as well as combinations of them. 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 --axis 2 --mode cuboid --verbose

Use the combination of diferent orientations:

neuroslice input.nii.gz output_mask.nii.gz --axis 0,1

Arguments:

Mandatory:

  • input: Path to input NIfTI file (.nii or .nii.gz)
  • output: Path to output mask NIfTI file

Optional:

  • --direction: Slice axis (RAS) - 0 (sagittal), 1 (coronal, default), 2 (axial)
  • --mode: Processing mode - union (default) or cuboid (bounding box)
  • --verbose: Print detailed statistics

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", axis=2, 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

cuboid_mask = mask2cuboid(mask)

Combine multiple masks:

from neuroslice import unite_masks

combined = unite_masks(mask1, mask2, mask3)

Advanced usage with direct predict function:

from neuroslice import predict, predict_multi_axis
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, mode="union", verbose=True)

mask_cuboid = predict_multi_axis(data, axis=[0,1], mode="cuboid"):

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. If you want to ask for changes, create an issue detailing what you want changed and someone will look into it.

More information on how to contribute can be found in the documentation.

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.4.tar.gz (5.6 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.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: neuroslice-1.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for neuroslice-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b2fc0d775e6d54504e850bf38f744d2408ff342852be0bb2dcbd235eb84fba56
MD5 2c8ca3b6249bb46fd4200888f9b591b1
BLAKE2b-256 44640725101a44555a50901dd216d74563f59c244e3b3dbf8321d82dd585199f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: neuroslice-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for neuroslice-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca51def24379b3388d1d8c870a2a7b9624c753bc3a1c25d79a1568947fed6d8c
MD5 602a0734803359447413831b79f09bf1
BLAKE2b-256 9ab378af23a158b67d2740779529ab4517fdc22d8de88e2b25f155d67f5ce4e2

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