Python implementation of Wu et al (2018)'s registration fusion

Overview

reg-fusion

logo
Projection of a central sulcus probability map using the RF-ANTs approach (right hemisphere shown).

This is a Python implementation of Wu et al (2018)'s registration fusion methods to project MRI data from standard volumetric coordinates, either MNI152 or Colin27, to Freesurfer's fsaverage. This tool already available in the original MATLAB-based version provided by Wu et al, which works well out of the box. However, given Python's increasing stake in neuroimaging analysis, a pure Python version may be useful.

A huge thank you to Wu et al for making their excellent tool openly available! If you use this package, please cite the original:

Wu J, Ngo GH, Greve DN, Li J, He T, Fischl B, Eickhoff SB, Yeo BTT. Accurate nonlinear mapping between MNI volumetric and FreeSurfer surface coordinate systems, Human Brain Mapping 39:3793–3808, 2018.

Installation

This package requires Python 3. Installing regfusion is simple with pip:

pip install regfusion

If you want to build regfusion directly from source code, use the following code:

git clone https://github.com/danjgale/reg-fusion
cd reg-fusion
python setup.py install

Command-line interface

Registration fusion can be ran on the command-line using regfusion. The flags correspond to the original implemenation, with the exception of -t, which is specific to regfusion (see Notes).

usage: regfusion [-h] [-s input_vol] [-o output_dir] [-p template_type] [-r RF_type] [-i interp] [-t out_type]

optional arguments:
  -h, --help        show this help message and exit
  -s input_vol      Absolute path to input volume. Input should be in nifti format
  -o output_dir     Absolute path to output directory
  -p template_type  Type of volumetric template used in index files. Use MNI152_orig or Colin27_orig when -r is RF_ANTs. Use MNI152_norm or Colin27_norm when
                    -r is RF_M3Z. Otherwise, an exception is raised. Ensure that the template matches the standard space of -i (i.e., use MNI152_* if -i is
                    in MNI152-space). Default: MNI152_orig
  -r RF_type        Type of Registration Fusion approaches used to generate the mappings (RF_M3Z or RF_ANTs). RF_M3Z is recommended if data was registered
                    from subject's space to the volumetric atlas space using FreeSurfer. RF_ANTs is recommended if such registrations were carried out using
                    other tools, especially ANTs. Default: RF_ANTs
  -i interp         Interpolation (linear or nearest). If -g is label.gii, then interpolation is always set to nearest and a warning is raised. Default:
                    linear
  -t out_type       File type of surface files. nii.gz is true to the original Wu et al (2018) implementation. Note that gifti formats, either func.gii or
                    label.gii, are often preferred. Default: nii.gz

Python API

The CLI simply calls the main underlying function, vol_to_fsaverage. This function can imported directly in Python. In addition to saving the files to out_dir, the absolute file paths of the left and right surface files are returned.

vol_to_fsaverage(input_img, out_dir, template_type='MNI152_orig', 
                 rf_type='RF_ANTs', interp='linear', out_type='nii.gz'):

    Project volumetric data in standard space (MNI152 or Colin27) to 
    fsaverage 

    Parameters
    ----------
    input_img : niimg-like
        Input image in standard space (i.e. MNI152 or Colin27)
    out_dir : str
        Path to output directory (does not need to already exist)
    template_type : {'MNI152_orig', 'Colin27_orig', 'MNI152_norm', 'Colin27_norm'}
        Type of volumetric template used in index files. Use 'MNI152_orig' or 
        'Colin27_orig' when `rf_type` is 'RF_ANTs'. Use 'MNI152_norm' or 
        'Colin27_norm' when `rf_type` is 'RF_M3Z'. Otherwise, an exception is 
        raised. Ensure that the template matches the standard space of 
        `input_img` (i.e., use MNI152_* if `input_img` is in MNI152-space). By 
        default 'MNI152_orig'.
    rf_type : {'RF_ANTs', 'RF_M3Z'}
        Type of Registration Fusion approaches used to generate the mappings.
        RF-M3Z is recommended if data was registered from subject's space to 
        the volumetric atlas space using FreeSurfer. RF-ANTs is recommended if 
        such registrations were carried out using other tools, especially 
        ANTs. By default 'RF_ANTs'
    interp : {'linear', 'nearest'}, optional
        Interpolation approach. If `out_type` is 'label.gii', then interpolation 
        is always set to 'nearest'. By default 'linear'
    out_type : {'nii.gz, 'func.gii', 'label.gii'}, optional
        File type of surface files. Default is 'nii.gz', which is true to the 
        original Wu et al (2018) implementation. Note that gifti 
        formats, either 'func.gii' or 'label.gii', are often preferred.

    Returns
    ----------
    str, str
        Absolute paths to left and right hemisphere output files, respectively

Examples

1. MNI to fsaverage (default)

For example, the default RF-ANTs implementation (preferred) with MNI data would be:

CLI:
regfusion -s mni_input.nii.gz -o output

Python:
from regfusion import vol_to_fsaverage
lh, rh = vol_to_fsaverage('mni_input.nii.gz', 'output')

True to the original implementation, two surface files (one each hemisphere) are saved to the output directory with the RF method and template embedded in the file names:

output/
  lh.mni_input.allSub_RF_ANTs_MNI152_orig_to_fsaverage.nii.gz
  rh.mni_input.allSub_RF_ANTs_MNI152_orig_to_fsaverage.nii.gz

2. MNI to fsaverage (GIfTI)

It may be preferred to generate GIfTI files instead of the default NIfTI:

CLI:
regfusion -s mni_input.nii.gz -o output -t func.gii

Python:
from regfusion import vol_to_fsaverage
lh, rh = vol_to_fsaverage('mni_input.nii.gz', 'output', out_type='func.gii')

The output, which will have the appropriate GIfTI file extensions:

output/
  lh.mni_input.allSub_RF_ANTs_MNI152_orig_to_fsaverage.func.gii
  rh.mni_input.allSub_RF_ANTs_MNI152_orig_to_fsaverage.func.gii

3. Projecting to label.gii

Should you wish to project a binary mask (e.g., to display a region of interest), you may consider setting the output type, -t, to label.gii. In this case, interpolation, -i, will always be set to nearest to retain the original voxel values/labels. If not explicitly set with -i, interpolation will be overwritten to nearest and warning is raised.

For example:

CLI:
regfusion -s mni_input.nii.gz -o output -i nearest -t label.gii

Python:
from regfusion import vol_to_fsaverage
lh, rh = vol_to_fsaverage('mni_input.nii.gz', 'output', interp='nearest', out_type='label.gii')

The output, which will have the appropriate GIfTI file extensions:

output/
  lh.mni_input.allSub_RF_ANTs_MNI152_orig_to_fsaverage.label.gii
  rh.mni_input.allSub_RF_ANTs_MNI152_orig_to_fsaverage.label.gii

4. MNI to fsaverage with RF-M3Z

And finally, the RF-M3Z method can be used if that is preferred:

CLI:
regfusion -i mni_input.nii.gz -o output -p MNI152_norm -r RF_M3Z

Python:
from regfusion import vol_to_fsaverage
lh, rh = vol_to_fsaverage('mni_input.nii.gz', 'output', template_type='MNI152_norm', rf_type='RF_M3Z')

The output, with different file names reflecting the method/template used:

output/
  lh.mni_input.allSub_RF_M3Z_MNI152_norm_to_fsaverage.nii.gz
  rh.mni_input.allSub_RF_M3Z_MNI152_norm_to_fsaverage.nii.gz

Notes

regfusion implements the same two registration fusion approaches by Wu et al, and is validated against the original MATLAB version (see tests/). However, there are some differences in the API:

  • regfusion does not have the -n flag that determines the number of subjects used to create the average mapping. That is because the standalone scripts of the MATLAB versions only uses all 1490 subjects, and thus regfusion does too
  • regfusion does not have the -m flag because no MATLAB is required
  • regfusion does not have the -f flag because, technically, Freesurfer is not required. However, it is strongly recommended that you have a freely available Freesurfer license because we are ultimately projecting to Freesurfer's fsaverage
  • Unlike the original MATLAB version, regfusion has a -t flag (out_type in vol_to_fsaverage; see above for description). The original MATLAB version outputs NIfTI images (regfusion default), but this option lets regfusion output to GIfTIs, which are generally preferred for surface files. Users are encouraged to set -t/out_type to one of the GIfTI output types if they find that GIfTIs are more suitable for their needs

Some useful things to know:

  • Wu et al show that RF-ANTs is generally the better approaches of the two, which is why it's the default in regfusion. RF-M3Z seems best-suited if the normalization was performed via Freesurfer.
  • As Wu et al emphasize, the actual best practice here avoid projecting standard volumetric coordinates (e.g., MNI) to fsaverage altogether. Alternatives include performing all you analyses in subject/native volumetric coordinates and projecting that data to fsaverage, based on Freesurfer's recon-all. Or, perform analyses directly in fsaverage after running recon-all. Projecting data from one standard coordinates space to another is loses precision at each step (see Wu et al for details). Neverthless, people do this all the time and these registration fusion approaches ensure that these projections are as accurate as possible.
  • Relating to the previous point: If you do project from MNI/Colin coordinates to fsaverage, it's probably a wise idea to find a way to still show your data in volume-space too (e.g., as supplementary figures/material).

References

Wu J, Ngo GH, Greve DN, Li J, He T, Fischl B, Eickhoff SB, Yeo BTT. Accurate nonlinear mapping between MNI volumetric and FreeSurfer surface coordinate systems, Human Brain Mapping 39:3793–3808, 2018.

Owner
Dan Gale
Neuroscience PhD candidate with an interest in data science and software development.
Dan Gale
SegNet-Basic with Keras

SegNet-Basic: What is Segnet? Deep Convolutional Encoder-Decoder Architecture for Semantic Pixel-wise Image Segmentation Segnet = (Encoder + Decoder)

Yad Konrad 81 Jun 30, 2022
《DeepViT: Towards Deeper Vision Transformer》(2021)

DeepViT This repo is the official implementation of "DeepViT: Towards Deeper Vision Transformer". The repo is based on the timm library (https://githu

109 Dec 02, 2022
Vision transformers (ViTs) have found only limited practical use in processing images

CXV Convolutional Xformers for Vision Vision transformers (ViTs) have found only limited practical use in processing images, in spite of their state-o

Cloudwalker 23 Sep 10, 2022
Code for "Unsupervised Layered Image Decomposition into Object Prototypes" paper

DTI-Sprites Pytorch implementation of "Unsupervised Layered Image Decomposition into Object Prototypes" paper Check out our paper and webpage for deta

40 Dec 22, 2022
PyTorch Implementation of Small Lesion Segmentation in Brain MRIs with Subpixel Embedding (ORAL, MICCAIW 2021)

Small Lesion Segmentation in Brain MRIs with Subpixel Embedding PyTorch implementation of Small Lesion Segmentation in Brain MRIs with Subpixel Embedd

22 Oct 21, 2022
"NAS-Bench-301 and the Case for Surrogate Benchmarks for Neural Architecture Search".

NAS-Bench-301 This repository containts code for the paper: "NAS-Bench-301 and the Case for Surrogate Benchmarks for Neural Architecture Search". The

AutoML-Freiburg-Hannover 57 Nov 30, 2022
Code repository for Semantic Terrain Classification for Off-Road Autonomous Driving

BEVNet Datasets Datasets should be put inside data/. For example, data/semantic_kitti_4class_100x100. Training BEVNet-S Example: cd experiments bash t

(Brian) JoonHo Lee 24 Dec 12, 2022
Scikit-learn compatible estimation of general graphical models

skggm : Gaussian graphical models using the scikit-learn API In the last decade, learning networks that encode conditional independence relationships

213 Jan 02, 2023
Self-supervised learning algorithms provide a way to train Deep Neural Networks in an unsupervised way using contrastive losses

Self-supervised learning Self-supervised learning algorithms provide a way to train Deep Neural Networks in an unsupervised way using contrastive loss

Arijit Das 2 Mar 26, 2022
Pytorch implementation of 'Fingerprint Presentation Attack Detector Using Global-Local Model'

RTK-PAD This is an official pytorch implementation of 'Fingerprint Presentation Attack Detector Using Global-Local Model', which is accepted by IEEE T

6 Aug 01, 2022
Unsupervised Feature Ranking via Attribute Networks.

FRANe Unsupervised Feature Ranking via Attribute Networks (FRANe) converts a dataset into a network (graph) with nodes that correspond to the features

7 Sep 29, 2022
A pure PyTorch implementation of the loss described in "Online Segment to Segment Neural Transduction"

ssnt-loss ℹ️ This is a WIP project. the implementation is still being tested. A pure PyTorch implementation of the loss described in "Online Segment t

張致強 1 Feb 09, 2022
Human Dynamics from Monocular Video with Dynamic Camera Movements

Human Dynamics from Monocular Video with Dynamic Camera Movements Ri Yu, Hwangpil Park and Jehee Lee Seoul National University ACM Transactions on Gra

215 Jan 01, 2023
Implement the Pareto Optimizer and pcgrad to make a self-adaptive loss for multi-task

multi-task_losses_optimizer Implement the Pareto Optimizer and pcgrad to make a self-adaptive loss for multi-task 已经实验过了,不会有cuda out of memory情况 ##Par

14 Dec 25, 2022
RoFormer_pytorch

PyTorch RoFormer 原版Tensorflow权重(https://github.com/ZhuiyiTechnology/roformer) chinese_roformer_L-12_H-768_A-12.zip (提取码:xy9x) 已经转化为PyTorch权重 chinese_r

yujun 283 Dec 12, 2022
a basic code repository for basic task in CV(classification,detection,segmentation)

basic_cv a basic code repository for basic task in CV(classification,detection,segmentation,tracking) classification generate dataset train predict de

1 Oct 15, 2021
A super lightweight Lagrangian model for calculating millions of trajectories using ERA5 data

Easy-ERA5-Trck Easy-ERA5-Trck Galleries Install Usage Repository Structure Module Files Version iteration Easy-ERA5-Trck is a super lightweight Lagran

Zhenning Li 26 Nov 19, 2022
A wrapper around SageMaker ML Lineage Tracking extending ML Lineage to end-to-end ML lifecycles, including additional capabilities around Feature Store groups, queries, and other relevant artifacts.

ML Lineage Helper This library is a wrapper around the SageMaker SDK to support ease of lineage tracking across the ML lifecycle. Lineage artifacts in

AWS Samples 12 Nov 01, 2022
TAP: Text-Aware Pre-training for Text-VQA and Text-Caption, CVPR 2021 (Oral)

TAP: Text-Aware Pre-training TAP: Text-Aware Pre-training for Text-VQA and Text-Caption by Zhengyuan Yang, Yijuan Lu, Jianfeng Wang, Xi Yin, Dinei Flo

Microsoft 61 Nov 14, 2022
FPSAutomaticAiming——基于YOLOV5的FPS类游戏自动瞄准AI

FPSAutomaticAiming——基于YOLOV5的FPS类游戏自动瞄准AI 声明: 本项目仅限于学习交流,不可用于非法用途,包括但不限于:用于游戏外挂等,使用本项目产生的任何后果与本人无关! 简介 本项目基于yolov5,实现了一款FPS类游戏(CF、CSGO等)的自瞄AI,本项目旨在使用现

Fabian 246 Dec 28, 2022