The regfusionr package implements Wu et
al. (2018)’s registration fusion methods in R. It provides accurate
nonlinear mapping between three standard coordinate systems commonly
used in neuroimaging:
If you use this package, please cite the original paper:
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.
All examples in this vignette require a working FreeSurfer installation.
The FREESURFER_HOME environment variable must be set to the
FreeSurfer installation directory (e.g.,
/Applications/freesurfer/7.4.0), or you can pass the path
explicitly via the fs_home parameter.
If you have properly installed and configured FreeSurfer, this should
already be the case. You can check that the FREESURFER_HOME
environment variable is set correctly:
The vol_to_fsaverage() function additionally requires
the oce package for trilinear interpolation. The
fsaverage_to_vol() function requires fsbrain
and haze. These are optional dependencies and can be
installed as needed.
The most common use case: you have a peak coordinate from an fMRI paper in MNI152 space, and you want to know where it is on the fsaverage surface.
Convenience functions let you map directly between MNI152 and Colin27 space via fsaverage.
Instead of mapping individual coordinates, you can project an entire 3D or 4D volume to per-vertex surface data.
# Project an MNI152 volume file to fsaverage surface space.
# The result is stored in R memory (out_dir = NULL).
input_file = system.file("extdata", "testdata",
"MNI_probMap_ants.central_sulc.nii.gz", package = "regfusionr")
res = vol_to_fsaverage(input_file, template_type = 'MNI152_orig',
rf_type = 'RF_ANTs', out_dir = NULL)
# res$lh: per-vertex data for the left hemisphere (numeric vector, length 163842)
# res$rh: per-vertex data for the right hemisphere
# To write output files instead, specify an out_dir.
out_dir = tempfile("regfusionr_output_")
res = vol_to_fsaverage(input_file, template_type = 'MNI152_orig',
rf_type = 'RF_ANTs', out_type = 'curv', out_dir = out_dir)
# res$lh and res$rh now contain file paths to the written curv files.Convert per-vertex fsaverage data (e.g., cortical thickness maps) to an MNI152 or Colin27 volume.
# Create synthetic per-vertex data (fsaverage: 163842 vertices per hemisphere).
lh_data = rnorm(163842L, 3.0, 0.2)
rh_data = rnorm(163842L, 3.0, 0.2)
# Project to MNI152 volume space using linear interpolation.
# The result is kept in memory only (out_dir = NULL).
res = fsaverage_to_vol(lh_data, rh_data, target_space = "FSL_MNI152",
interp = "linear", out_dir = NULL)
# res$projected: fs.volume instance with a 256x256x256 data array.
# res$projected_seg: same, but right-hemisphere values incremented by 1000
# (useful for distinguishing hemispheres in labels).For categorical label data, use interp = "nearest":
If you have MNI305 (fsaverage) coordinates and want MNI152 or Colin27 coordinates, you can find the closest fsaverage vertex and map it.
# Get MNI305 coords of fsaverage vertex 9092 from the orig surface.
fsaverage_home = file.path(Sys.getenv("FREESURFER_HOME"), "subjects")
rh_orig = freesurferformats::read.fs.surface(
file.path(fsaverage_home, "fsaverage", "surf", "rh.orig"))
mni305_pt = rh_orig$vertices[9092L, ]
# Map to MNI152.
mni152_coords = mni305_coords_to_mni152_coords(mni305_pt)
# Map to Colin27.
c27_coords = mni305_coords_to_colin27_coords(mni305_pt)The package also includes the linear 4×4 matrix method from the FreeSurfer documentation, which you can use to compare accuracy with the nonlinear regfusion approach.
The package supports two registration fusion approaches:
MNI152_orig or
Colin27_orig templates.MNI152_norm or
Colin27_norm templates.For the coordinate-mapping functions
(mni152_coords_to_fsaverage,
colin27_coords_to_fsaverage), RF-M3Z uses a fallback
.txt-based nearest-vertex method. The RF-ANTs MNI152
combination uses a faster pre-computed vertex index volume.