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
GDR-Net: Geometry-Guided Direct Regression Network for Monocular 6D Object Pose Estimation. (CVPR 2021)

GDR-Net This repo provides the PyTorch implementation of the work: Gu Wang, Fabian Manhardt, Federico Tombari, Xiangyang Ji. GDR-Net: Geometry-Guided

169 Jan 07, 2023
MoveNet Single Pose on DepthAI

MoveNet Single Pose tracking on DepthAI Running Google MoveNet Single Pose models on DepthAI hardware (OAK-1, OAK-D,...). A convolutional neural netwo

64 Dec 29, 2022
Constructing interpretable quadratic accuracy predictors to serve as an objective function for an IQCQP problem that represents NAS under latency constraints and solve it with efficient algorithms.

IQNAS: Interpretable Integer Quadratic programming Neural Architecture Search Realistic use of neural networks often requires adhering to multiple con

0 Oct 24, 2021
Diffgram - Supervised Learning Data Platform

Data Annotation, Data Labeling, Annotation Tooling, Training Data for Machine Learning

Diffgram 1.6k Jan 07, 2023
Code for "Hierarchical Skills for Efficient Exploration" HSD-3 Algorithm and Baselines

Hierarchical Skills for Efficient Exploration This is the source code release for the paper Hierarchical Skills for Efficient Exploration. It contains

Facebook Research 38 Dec 06, 2022
Kaggle-titanic - A tutorial for Kaggle's Titanic: Machine Learning from Disaster competition. Demonstrates basic data munging, analysis, and visualization techniques. Shows examples of supervised machine learning techniques.

Kaggle-titanic This is a tutorial in an IPython Notebook for the Kaggle competition, Titanic Machine Learning From Disaster. The goal of this reposito

Andrew Conti 800 Dec 15, 2022
Optimizing DR with hard negatives and achieving SOTA first-stage retrieval performance on TREC DL Track (SIGIR 2021 Full Paper).

Optimizing Dense Retrieval Model Training with Hard Negatives Jingtao Zhan, Jiaxin Mao, Yiqun Liu, Jiafeng Guo, Min Zhang, Shaoping Ma 🔥 News 2021-10

Jingtao Zhan 99 Dec 27, 2022
A python/pytorch utility library

A python/pytorch utility library

Jiaqi Gu 5 Dec 02, 2022
EDPN: Enhanced Deep Pyramid Network for Blurry Image Restoration

EDPN: Enhanced Deep Pyramid Network for Blurry Image Restoration Ruikang Xu, Zeyu Xiao, Jie Huang, Yueyi Zhang, Zhiwei Xiong. EDPN: Enhanced Deep Pyra

69 Dec 15, 2022
Official code repository for the work: "The Implicit Values of A Good Hand Shake: Handheld Multi-Frame Neural Depth Refinement"

Handheld Multi-Frame Neural Depth Refinement This is the official code repository for the work: The Implicit Values of A Good Hand Shake: Handheld Mul

55 Dec 14, 2022
Code for the ICCV2021 paper "Personalized Image Semantic Segmentation"

PSS: Personalized Image Semantic Segmentation Paper PSS: Personalized Image Semantic Segmentation Yu Zhang, Chang-Bin Zhang, Peng-Tao Jiang, Ming-Ming

张宇 15 Jul 09, 2022
Doosan robotic arm, simulation, control, visualization in Gazebo and ROS2 for Reinforcement Learning.

Robotic Arm Simulation in ROS2 and Gazebo General Overview This repository includes: First, how to simulate a 6DoF Robotic Arm from scratch using GAZE

David Valencia 12 Jan 02, 2023
Code for T-Few from "Few-Shot Parameter-Efficient Fine-Tuning is Better and Cheaper than In-Context Learning"

T-Few This repository contains the official code for the paper: "Few-Shot Parameter-Efficient Fine-Tuning is Better and Cheaper than In-Context Learni

220 Dec 31, 2022
FCA: Learning a 3D Full-coverage Vehicle Camouflage for Multi-view Physical Adversarial Attack

FCA: Learning a 3D Full-coverage Vehicle Camouflage for Multi-view Physical Adversarial Attack Case study of the FCA. The code can be find in FCA. Cas

IDRL 21 Dec 15, 2022
Python library for tracking human heads with FLAME (a 3D morphable head model)

Video Head Tracker 3D tracking library for human heads based on FLAME (a 3D morphable head model). The tracking algorithm is inspired by face2face. It

61 Dec 25, 2022
Minecraft Hack Detection With Python

Minecraft Hack Detection An attempt to try and use crowd sourced replays to find

Kuleen Sasse 3 Mar 26, 2022
Global-Local Attention for Emotion Recognition

Global-Local Attention for Emotion Recognition Requirements Python 3 Install tensorflow (or tensorflow-gpu) = 2.0.0 Install some other packages pip i

Minh Nhat Le 15 Apr 21, 2022
The dataset of tweets pulling from Twitters with keyword: Hydroxychloroquine, location: US, Time: 2020

HCQ_Tweet_Dataset: FREE to Download. Keywords: HCQ, hydroxychloroquine, tweet, twitter, COVID-19 This dataset is associated with the paper "Understand

2 Mar 16, 2022
YOLOv2 in PyTorch

YOLOv2 in PyTorch NOTE: This project is no longer maintained and may not compatible with the newest pytorch (after 0.4.0). This is a PyTorch implement

Long Chen 1.5k Jan 02, 2023
A python3 tool to take a 360 degree survey of the RF spectrum (hamlib + rotctld + RTL-SDR/HackRF)

RF Light House (rflh) A python script to use a rotor and a SDR device (RTL-SDR or HackRF One) to measure the RF level around and get a data set and be

Pavel Milanes (CO7WT) 11 Dec 13, 2022