Skip to main content

wrapper for brain segmentation tools

Project description

BrainSeg-container

This repository provides a streamlined Python wrapper and CLI tool to automatically download, run, and standardize outputs from state-of-the-art brain segmentation tools using Apptainer / Singularity containers.

Brain segmentation tools often have conflicting dependencies, complex installation steps, or require specific versions of system libraries. This package solves that problem by containerizing the tools and handling the execution, file binding, and label standardization for you.

h:8cm

The Tools

This pipeline currently supports the following deep-learning-based segmentation tools. We may add more in the future.

  1. GOUHFI This tool was designed to handle the challenges of Ultra-High Field MRI (7T+). It utilizes "domain randomization" during training, which allows it to remain robust across different MRI contrasts and resolutions, including standard clinical scans.

    • Resolution: Native (preserves input resolution).

    • CSF Availability: Yes (segments ventricles and subarachnoid space CSF).

  2. SynthSeg Developed by the FreeSurfer team, this tool is famous for working "out of the box" on almost any kind of MRI scan (different contrasts, resolutions, or messy clinical data).

    • Resolution: Fixed 1mm isotropic (always resamples input to 1mm).

    • CSF Availability: Yes.

  3. FastSurfer A rapid deep-learning-based segmentation tool.

    • Resolution: Native (but experimental below 0.7mm).

    • CSF Availability: No (segments ventricles, but ignores subarachnoid space CSF).

  4. SimNIBS (Charm) The "Complete Head Anatomy Reconstruction Method" from the SimNIBS suite. While designed for modeling brain stimulation (TMS/TES), it produces high-quality segmentation of extra-cerebral tissues (skull, scalp, etc.) in addition to the brain.

    • Resolution: Native (pipeline uses the upsampled output to match input).

    • CSF Availability: Yes.

    • Segmented regions: Charm provides the following segmentation labels: White-Matter, Gray-Matter, CSF, Bone, Scalp, Eye_bals, Compact_bone, Spongy_bone, Blood, Muscle, Cartilage, Fat, Electrode, Saline_or_gel

Comparison Output

The pipeline can automatically generate a comparison grid so you can quickly inspect the differences between the tools.

Getting Started

Prerequisites

You must have Apptainer (or Singularity) installed on your system to run the containers.

  • Ubuntu/Debian: sudo apt install apptainer
  • Conda/Mamba: conda install -c conda-forge apptainer

Installation

You can install the package directly via pip:

pip install brainseg-containers

(Optional) If you want to use the plotting and comparison features, install with the plot extras:

pip install brainseg-containers[plot]

Usage

The package provides a simple command-line interface. The first time you run a specific tool, the wrapper will automatically download the corresponding container from the GitHub Container Registry and store it in ~/.brainseg_containers/.

Basic Command

brainseg -t <tool_name> -i <input_file.nii.gz> -o <output_file.nii.gz>

Available Tools: synthseg, gouhfi, fastsurfer, simnibs

Examples

Run GOUHFI on a single subject:

brainseg -t gouhfi -i inputs/sub-01_T1w.nii.gz -o results/sub-01_gouhfi.nii.gz

Run SynthSeg on the same subject:

brainseg -t synthseg -i inputs/sub-01_T1w.nii.gz -o results/sub-01_synthseg.nii.gz

Note: You can optionally provide a custom path to a pre-downloaded .sif image using the --container flag.

Note on Labels

Different tools use different numbers to represent brain regions. To make comparison easier, this pipeline automatically remaps the output labels of FastSurfer and GOUHFI to match the standard FreeSurfer lookup table.

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

brainseg_containers-1.0.2.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

brainseg_containers-1.0.2-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file brainseg_containers-1.0.2.tar.gz.

File metadata

  • Download URL: brainseg_containers-1.0.2.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brainseg_containers-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0b0423a5c9aa56219c552620563c296c9d06a2ef60ded69d48dcdb1c12142967
MD5 8502c6bff867f71ff869cb66c203239b
BLAKE2b-256 3175c8a1e3e5bb38ef8d32c3782425514e6438a4b455d26748c0d758b7c1b558

See more details on using hashes here.

File details

Details for the file brainseg_containers-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for brainseg_containers-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e81bbf4ea89b2e00ba82436af74608d14315a08e89e9bc132a8a5ec22a9c6c4c
MD5 7a83c36cd0f758b6fc4148990c4776a6
BLAKE2b-256 388a2c22d72cb9e8bf329f900250aaf8cd326f5babe42d74c5aa932cb3a19693

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