Sign inSign up

aparida12/brainseg

By aparida12

Updated over 4 years ago

Anatomy Based GM, WM and CSF Segmentation of Brain MRI

Image
0

1.6K

aparida12/brainseg repository overview

Anatomy Based GM, WM and CSF Segmentation

In this repository, we repurpose the SynthSeg based model to do Gray Matter(GM), White Matter(WM) and Cerebro-Spinal Fluid(CSF) segmentation for MRI of the brain. Using medical information we assign each of the anatomical region from the synthseg into one of the categories. This process is also configurable. The method is dockerised in to allow for plug and play approach.

Sample Segmentation Result
Easily segment your data with one command

Once all the docker and its dependencies are installed, you can simply test brain matter segmentation on your own data with:

Run with GPUs:

default:

docker run --gpus all --user "$(id -u):$(id -g)" -v <inpdir>:/synthseg/inp -v <outdir>:/synthseg/out aparida12/brainseg

with additional flags:

docker run --gpus all --user "$(id -u):$(id -g)" -v <inpdir>:/synthseg/inp -v <outdir>:/synthseg/out aparida12/brainseg python -u run_seg.py <optional_flags>

Run without GPUs:

default:

docker run --user "$(id -u):$(id -g)" -v <inpdir>:/synthseg/inp -v <outdir>:/synthseg/out aparida12/brainseg

with additional flags:

docker run --user "$(id -u):$(id -g)" -v <inpdir>:/synthseg/inp -v <outdir>:/synthseg/out aparida12/brainseg python -u run_seg.py <optional_flags>

where:

  • <inpdir> is the directory with all nifti files(extn .nii.gz or .nii) that need to be segmented.
  • <outdir> is the directory where all outputs are stored(<inpdir> should not be <outdir>).


Additional optional flags are also available:

  • --cpu: to enforce the code to run on the CPU, even if a GPU is available.
  • --threads: to indicate the number of cores to be used if running on a CPU (example: --threads 3 to run on 3 cores). This value defaults to 1, but we recommend increasing it for faster analysis.
  • --crop: to crop the input images to a given shape before segmentation. The given size must be divisible by 32. Images are cropped around their center, and their segmentations are given at the original size). It can be given as a single (i.e., --crop 160 to run on 1603 patches), or several integers (i.e, --crop 160 128 192 to crop to different sizes in each direction, ordered in RAS coordinates). This value defaults to 192, but it can be decreased for faster analysis or to fit in your GPU.

IMPORTANT:, Unlike the original synthseg, we resample the synthseg output to its original voxel dimension. So both the anatomy maps and the region maps are overlay able on the original input MRI.


Input Folder Structure

The seg_config.yaml is optional inside the <inpdir>. It is only required when the user wants to change the classification of the default anatomy into different regions than in the default seg_config.yaml

│
└───<inpdir>
│   │   file011.nii.gz
│   │   file012.nii.gz
│   │   file012.nii.gz
│   │.  seg_config.yaml


Output Folder Structure

After processing is over the <outdir> has folders - anatomy_seg and matter_seg.

where:

  • anatomy_seg is the directory where the files with the different brain structures are segmented separately(the resampled to original size output of the SynthSeg algorithm)
  • matter_seg is the directory where the files where the anatomies are aggregated into different regions like GM, WM, CSF, and others as specified by the seg_config.yaml
  • labels.txt is a TXT file that has the mapping between pixel values of the nifti file with the corresponding name of the structure or region and some suggested color scheme that can be used by ITKSnap in the segmentation mode.
│
└───<outdir>
│   │─── anatomy_seg
│   │   │   │seg_file011.nii.gz
│   │   │   │seg_file012.nii.gz
│   │   │   │seg_file012.nii.gz
│   │   │   │.  labels.txt
│   │
│   │─── matter_seg
│   │   │   │seg_file011.nii.gz
│   │   │   │seg_file012.nii.gz
│   │   │   │seg_file012.nii.gz
│   │   │   │.  labels.txt


User Specified seg_config.yaml

Download the template seg_config.yaml from here(You can right-click save-as seg_config.yaml). Modify the various regions by following the steps mentioned in the YAML file. Do not forget to put the modified file inside the <inpdir> along with the other Nifti Files.




Tag summary

Content type

Image

Digest

Size

1.9 GB

Last updated

over 4 years ago

docker pull aparida12/brainseg