Deletions are marked like this. | Additions are marked like this. |
Line 14: | Line 14: |
A preprint of the manuscript describing the atlas and segmentation method used in this module can be found [[https://www.biorxiv.org/content/10.1101/2024.02.05.579016v1|on bioRxiv.]] | A preprint of the manuscript describing the atlas and segmentation method used in this module can be found [[https://www.biorxiv.org/content/10.1101/2024.02.05.579016v1|on bioRxiv.]] |
Line 19: | Line 19: |
3. Usage ('full' Bayesian version; not recommended) 4. Usage (fast version) |
3. Usage ('full' Bayesian version, '''not recommended''') 4. Usage (faster versions) |
Line 29: | Line 29: |
The first time you run this module, it will prompt you to download the atlas. Follow the instructions on the screen to obtain the files. | The first time you run this module, it will prompt you to download the atlas. Follow the instructions on the screen to obtain the files. |
Line 32: | Line 32: |
=== 3. Usage ('full' Bayesian version; not recommended, see fast version below) === To segment a brain MRI scan, |
=== 3. Usage ('full' Bayesian version; not recommended as it is very slow) === To segment a brain MRI scan, |
Line 45: | Line 45: |
''GPU'': set to 1 to use the GPU ('''we highly recommend using a GPU to run this module; without a GPU, running this module on a single scan can take a whole day'''). The GPU requirements depend on the image but are about 24GB of memory. | ''GPU'': set to 1 to use the GPU ('''we highly recommend using a GPU to run this module; without a GPU, running this module on a single scan can take tens for hours'''). The GPU requirements depend on the image but are about 24GB of memory. |
Line 58: | Line 58: |
mri_histo_atlas_segment $SUBJECTS_DIR/bert/mri/orig.mgz $SUBJECTS_DIR/bert/mri/histo_atlas_segmentation/ simplified 1 8 | mri_histo_atlas_segment $SUBJECTS_DIR/bert/mri/orig.mgz $SUBJECTS_DIR/bert/mri/histo_atlas_segmentation/ simplified 1 8 |
Line 69: | Line 69: |
''seg_[left/right].mgz'': segmentation into 333 ROIs of the left and right hemisphere, respectively. | ''seg_[left/right].mgz'': segmentation into 333 ROIs of the left and right hemisphere, respectively. |
Line 77: | Line 77: |
=== 4. Usage (fast version) === We also distribute a fast version, where the atlas deformation is pre-computed with a neural network, |
=== 4. Usage (faster versions) === We also distribute two faster version, where the atlas deformation is pre-computed |
Line 81: | Line 82: |
There are two sub-versions. One uses [[https://arxiv.org/abs/2404.01249|FireANTs (Jena et al)]] to register to the target scan a synthetic cartoon derived from the atlas. This version actively tries to fit smaller structures and subregions. The command line is: {{{ mri_histo_atlas_segment_fireants INPUT_SCAN OUTPUT_DIRECTORY GPU THREADS [BF_MODE] }}} The other version uses [[https://arxiv.org/abs/2404.01249|SynthMorph (Hoffmann et al., Imaging Neuroscience, 2024)]], a neural network for image registration. This version is faster and does OK for 1mm isotropic scans. However, SynthMorph relies heavily on fitting the boundaries of whole structures and does not the map smaller regions as well (e.g., thalamic nuclei). Therefore, we do not recommend it for images with resolution better than 1mm isotropic (e.g., ex vivo scans). |
|
Line 86: | Line 102: |
The options are similar to mri_histo_atlas_segment, but the atlas and gmm modes are always 'simplified' and '1mm', respectively. | For both commands, the options are similar to mri_histo_atlas_segment, but the atlas and gmm modes are always 'simplified' and '1mm', respectively. |
Line 89: | Line 105: |
This faster version is particularly useful if you are running the code on the CPU rather than CPU. On a semi-modern desktop, the run time should be less than an hour (note that it segments both hemispheres in a single run, as opposed to the full Bayesian version). |
These faster versions are particularly useful if you are running the code on the CPU rather than CPU. On a semi-modern desktop, the run time should be less than an hour; note that mri_histo_atlas_segment_fireants runs once per hemisphere, whhile mri_histo_atlas_segment_fast segments both hemispheres in a single run. |
Line 102: | Line 120: |
* '''Do I need a GPU for the fast version?''' | * '''Do I need a GPU for the faster versions?''' |
Line 104: | Line 122: |
Certainly no! The code should run in less than an hour on any semi-modern workstation, if you allocate enough threads. | Certainly no! The code should run in less than an hour on any semi-modern workstation, if you allocate enough threads (or about two hours for an ex vivo scan at 0.25mm resolution). |
Line 107: | Line 125: |
* '''What do the BF_MODE and GMM_MODE arguments do?''' | * '''What do the BF_MODE and GMM_MODE arguments do in the full Bayesian version?''' |
Line 109: | Line 127: |
You should not need to touch these, but the BF_MODE changes the set of basis functions for bias field correction and you could potentially try tinkering with it if the bias field correction fails (i.e., if bf_corrected.mgz has noticeable bias). GMM_MODE allows you to change the grouping of ROIs into tissue classes (advanced mode!). The GMM model is crucial as it determines how different brain regions are grouped into tissue types for the purpose of |
You should not need to touch these, but the BF_MODE changes the set of basis functions for bias field correction and you could potentially try tinkering with it if the bias field correction fails (i.e., if bf_corrected.mgz has noticeable bias). GMM_MODE allows you to change the grouping of ROIs into tissue classes (advanced mode!). The GMM model is crucial as it determines how different brain regions are grouped into tissue types for the purpose of |
Line 121: | Line 139: |
We distribute a GMM_MODE named "1mm" that we have used in our experiments, and which is the default mode of the code. If you want to use your own model, you will need to create another triplet of files of your own (use the 1mm version as template). |
We distribute a GMM_MODE named "1mm" that we have used in our experiments, and which is the default mode of the code. If you want to use your own model, you will need to create another triplet of files of your own (use the 1mm version as template). |
Bayesian Segmentation with Histological Atlas "NextBrain"
Visit the homepage of the NextBrain project for further information on this atlas.
Author: Juan Eugenio Iglesias
E-mail: jiglesiasgonzalez [at] mgh.harvard.edu
Rather than directly contacting the author, please post your questions on this module to the FreeSurfer mailing list at freesurfer [at] nmr.mgh.harvard.edu
A preprint of the manuscript describing the atlas and segmentation method used in this module can be found on bioRxiv.
Contents
- General Description
- Installation
Usage ('full' Bayesian version, not recommended)
- Usage (faster versions)
- Frequently asked questions (FAQ)
1. General Description
This module uses our new probabilistic atlas of the human brain to segment 333 distinct ROIs per hemisphere on in vivo scans. Segmentation relies on a Bayesian algorithm and is thus robust against changes in MRIi pulse sequence (e.g., T1-weighted, T2-weighted, FLAIR, etc). Sample slices of the atlas and the segmentation of the sample subject "bert" are shown below:
2. Installation
The first time you run this module, it will prompt you to download the atlas. Follow the instructions on the screen to obtain the files.
3. Usage ('full' Bayesian version; not recommended as it is very slow)
To segment a brain MRI scan,
mri_histo_atlas_segment INPUT_SCAN OUTPUT_DIRECTORY ATLAS_MODE GPU THREADS [BF_MODE] [GMM_MODE]
where:
INPUT_SCAN: scan to process, in mgz or nii(.gz) format.
OUTPUT_DIRECTORY: directory where segmentations, volume files, etc, will be created (more on this below).
ATLAS_MODE : full (atlas with all 333 labels) or simplified (simpler brainstem protocol; recommended)
GPU: set to 1 to use the GPU (we highly recommend using a GPU to run this module; without a GPU, running this module on a single scan can take tens for hours). The GPU requirements depend on the image but are about 24GB of memory.
THREADS: number of CPU threads used by the code (set to -1 to use all available threads).
BF_MODE (optional): bias field mode: dct (default), polynomial, or hybrid.
GMM_MODE (optional): gaussian mixture model (GMM) model must be 1mm unless you define your own (see FAQ below).
For example, you can segment bert with a GPU and 8 CPU threads with:
mri_histo_atlas_segment $SUBJECTS_DIR/bert/mri/orig.mgz $SUBJECTS_DIR/bert/mri/histo_atlas_segmentation/ simplified 1 8
In the output directory, you will find:
bf_corrected.mgz: a bias field corrected version of the input scan.
SynthSeg.mgz: SynthSeg segmentation of the input (which we use in preprocessing and to initialize Gaussian parameters).
MNI_registration.mgz: EasyReg registration to MNI space, use in preprocessing.
seg_[left/right].mgz: segmentation into 333 ROIs of the left and right hemisphere, respectively.
vols_[left/right].csv: CSV spreadsheet with the volumes of the different ROIs, computed from the posteriors (soft segmentations).
lookup_table.txt: FreeSurfer lookup table mapping label indices to brain anatomy. You need it when visualizing the segmentations with Freeview.
4. Usage (faster versions)
We also distribute two faster version, where the atlas deformation is pre-computed and then kept constant during the optimization, such that we only need to run the EM algorithm once for the Gaussian parameters and that is it.
There are two sub-versions. One uses FireANTs (Jena et al) to register to the target scan a synthetic cartoon derived from the atlas. This version actively tries to fit smaller structures and subregions. The command line is:
mri_histo_atlas_segment_fireants INPUT_SCAN OUTPUT_DIRECTORY GPU THREADS [BF_MODE]
The other version uses SynthMorph (Hoffmann et al., Imaging Neuroscience, 2024), a neural network for image registration. This version is faster and does OK for 1mm isotropic scans. However, SynthMorph relies heavily on fitting the boundaries of whole structures and does not the map smaller regions as well (e.g., thalamic nuclei). Therefore, we do not recommend it for images with resolution better than 1mm isotropic (e.g., ex vivo scans).
mri_histo_atlas_segment_fast INPUT_SCAN OUTPUT_DIRECTORY GPU THREADS [BF_MODE]
For both commands, the options are similar to mri_histo_atlas_segment, but the atlas and gmm modes are always 'simplified' and '1mm', respectively. The output files in the output directory follow the same convention.
These faster versions are particularly useful if you are running the code on the CPU rather than CPU. On a semi-modern desktop, the run time should be less than an hour; note that mri_histo_atlas_segment_fireants runs once per hemisphere, whhile mri_histo_atlas_segment_fast segments both hemispheres in a single run.
5. Frequently asked questions (FAQ)
Do I really need a GPU for the 'full' Bayesian version?
Technically, no. In practice, yes. On a modern GPU, the code runs in an hour or less. On the CPU, it depends on the number of threads, but it can easily take a whole day or more.
Do I need a GPU for the faster versions?
Certainly no! The code should run in less than an hour on any semi-modern workstation, if you allocate enough threads (or about two hours for an ex vivo scan at 0.25mm resolution).
What do the BF_MODE and GMM_MODE arguments do in the full Bayesian version?
You should not need to touch these, but the BF_MODE changes the set of basis functions for bias field correction and you could potentially try tinkering with it if the bias field correction fails (i.e., if bf_corrected.mgz has noticeable bias). GMM_MODE allows you to change the grouping of ROIs into tissue classes (advanced mode!). The GMM model is crucial as it determines how different brain regions are grouped into tissue types for the purpose of image intensity modeling. This is specified though a set of files that should be found under 'data' in the atlas directory:
data/gmm_components_[GMM_MODE].yaml: defines tissue classes and specificies the number of components of the corresponding GMM
data/combined_aseg_labels_[GMM_MODE].yaml defines the labels that belong to each tissue class
data/combined_atlas_labels_[GMM_MODE].yaml defines FreeSurfer ('aseg') labels that are used to initialize the parameters of each class.
Note that, in in dev versions newer than August 23 2024, these files are located under data_full and data_simplified (one directory per atlas / protocol).
We distribute a GMM_MODE named "1mm" that we have used in our experiments, and which is the default mode of the code. If you want to use your own model, you will need to create another triplet of files of your own (use the 1mm version as template).