Skip to main content

Automatic segmentation of epilepsy neurosurgery resection cavity.

Project description


Automatic segmentation of postoperative brain resection cavities from magnetic resonance images (MRI) using a convolutional neural network (CNN) trained with PyTorch 1.7.1.


It's recommended to use conda and install your desired PyTorch version before installing resseg. A 6-GB GPU is large enough to segment an image in the MNI space.

conda create -n resseg python=3.8 ipython -y && conda activate resseg  # recommended
pip install resseg


Below are two examples of cavity segmentation for tumor and epilepsy surgery. The epilepsy example includes registration to the MNI space. Both examples can be run online using Google Colab:

Open in Colab


Example using an image from the Brain Images of Tumors for Evaluation database (BITE).

BITE=`resseg-download bite`
resseg $BITE -o bite_seg.nii.gz

Resection cavity segmented on an image from BITE


Example using an image from the EPISURG dataset. Segmentation works best when images are in the MNI space, so resseg includes a tool for this purpose (requires ANTsPy).

pip install antspyx
EPISURG=`resseg-download episurg`
resseg-mni $EPISURG -t episurg_to_mni.tfm
resseg $EPISURG -o episurg_seg.nii.gz -t episurg_to_mni.tfm

Resection cavity segmented on an image from EPISURG

Trained model

The trained model can be used without installing resseg, but you'll need to install unet first:

pip install unet==0.7.7

Then, in Python:

import torch
repo = 'fepegar/resseg'
model_name = 'ressegnet'
model = torch.hub.load(repo, model_name, pretrained=True)


If you use this library for your research, please cite our MICCAI 2020 paper:

F. Pérez-García, R. Rodionov, A. Alim-Marvasti, R. Sparks, J. S. Duncan and S. Ourselin. Simulation of Brain Resection for Cavity Segmentation Using Self-Supervised and Semi-Supervised Learning.

[Preprint on arXiv]

And the EPISURG dataset, which was used to train the model:

Pérez-García, Fernando; Rodionov, Roman; Alim-Marvasti, Ali; Sparks, Rachel; Duncan, John; Ourselin, Sebastien (2020): EPISURG: a dataset of postoperative magnetic resonance images (MRI) for quantitative analysis of resection neurosurgery for refractory epilepsy. University College London. Dataset.

See also

  • resector was used to simulate brain resections during training
  • TorchIO was also used extensively. Both resseg and resector require this library.

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

resseg-0.3.6.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

resseg-0.3.6-py2.py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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