Differences between revisions 7 and 8
Deletions are marked like this. Additions are marked like this.
Line 85: Line 85:
Line 87: Line 87:
Line 89: Line 88:
Line 91: Line 89:
Line 93: Line 90:
Line 95: Line 91:
Line 97: Line 92:
Line 99: Line 93:
Line 101: Line 94:
Line 103: Line 95:



mri_vol2vol - Resamples a volume into another field-of-view using varous types of matrices (FreeSurfer, FSL, SPM, and MNI).




Required Flagged Arguments

--mov movvol

input (or output template with --inv)

--o outvol

output volume

Optional Flagged Arguments

--targ targvol

output template (or input with --inv)

--disp dispvol

displacement volume

--reg register.dat

tkRAS-to-tkRAS matrix (tkregister2 format)

--lta register.lta

Linear Transform Array (usually only 1 transform)

--fsl register.fsl

fslRAS-to-fslRAS matrix (FSL format)

--xfm register.xfm

ScannerRAS-to-ScannerRAS matrix (MNI format)


ScannerRAS-to-ScannerRAS matrix = identity


target MNI152 space (need FSL installed)

--s subject

set matrix = identity and use subject for any templates


sample from targ to mov


map to a sub FOV of MNI305 (with --reg only)

--talres resolution

set voxel size 1mm or 2mm (def is 1)

--talxfm xfmfile

default is talairach.xfm (looks in mri/transforms)

--m3z morph

non-linear morph encoded in the m3z format


flag indicating that the code should not be looking for the non-linear m3z morph in the default location (subj/mri/transforms), but should use the morph name as is


compute and use the inverse of the m3z morph

--fstarg <vol>

optionally use vol from subject in --reg as target. default is orig.mgz

--crop scale

crop and change voxel size

--slice-crop sS eE

crop output slices to be within sS and eE


reverse order of slices, update vox2ras

--slice-bias alpha

apply half-cosine bias field


trilinear interpolation (default)


nearest neighbor interpolation


cubic B-Spline interpolation

--interp interptype

interpolation cubic, trilin, nearest (default is trilin)

--mul mulval

multiply output by mulval

--precision precisionid

output precision (default is float)


set output precision to that of input


save the trilinear interpolation kernel instead


do not resample, just change vox2ras matrix

--rot Ax Ay Az

rotation angles (deg) to apply to reg matrix

--trans Tx Ty Tz

translation (mm) to apply to reg matrix

--shear Sxy Sxz Syz

xz is in-plane

--reg-final regfinal.dat

final reg after rot and trans (but not inv)


replace input with white Gaussian noise

--seed seed

seed for synth (default is to set from time of day)


write out output volume registration matrix



Resamples a volume into another field-of-view using various types of matrices (FreeSurfer, FSL, SPM, and MNI). This is meant to be used in conjunction with tkregister2.


The data file format can be specified implicitly (through the path name) or explicitly. All formats accepted by mri_convert can be used.


Example 1

If a functional volume is f.bhdr (or f.nii.gz, or f.mgh, etc), and the subject is bert, and the registration file is register.dat, then running the following command should show that they are in registration:

tkregister2 --reg register.dat --mov f.nii.gz

If they are not, then fix it because nothing below is going to work. You can also check the registration with:

tkmedit bert orig.mgz -overlay f.nii.gz -overlay-reg register.dat

The register.dat will look something like this:

1.000000e+00 0.000000e+00 0.000000e+00 -2.252487e+00
0.000000e+00 -8.902127e-01 4.555448e-01 2.342102e+00
0.000000e+00 4.555449e-01 8.902128e-01 -2.159538e-01
0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00

A. To resample the functional into anatomical space:

mri_vol2vol --reg register.dat --mov f.nii.gz --fstarg --o f-in-anat.mgh

f-in-anat.mgh will have the same size and geometry as bert/mri/orig.mgz. You can test the result in two ways:

  • This will show the low-res functional alighned with its resampled self:
    • tkregister2 --reg register.dat --mov f.nii.gz --targ f-in-anat.mgh
  • This will show the resampled functional aligned with the anatomical:
    • tkregister2 --mov f-in-anat.mgh --targ $SUBJECTS_DIR/bert/mri/orig.mgz \
      • --regheader --reg /tmp/reg

B. To resample the anatomical into the functional space. This is basically the same command line as 1.A, but --inv has been included and the name of the output is changed.

mri_vol2vol --reg register.dat --mov f.nii.gz --fstarg --o anat-in-func.mgh --inv

anat-in-func.mgh will be the same size and geometry as f.nii.gz. You can test the result in two ways:

  • This will show the low-res anat aligned with its hires self:
    • tkregister2 --reg register.dat --mov anat-in-func.mgh
  • This will show the resampled anat aligned with the functional:
    • tkregister2 --mov anat-in-func.mgh --targ f.nii.gz --regheader --reg /tmp/reg

C. Map functional to anatomical without resampling. Rather, change the vox2ras (sform/qform) matrix. This is the same cmd line as 1.A, but --no-resample as been added.

mri_vol2vol --reg register.dat --mov f.nii.gz --fstarg --o f.new.vox2ras.nii.gz --no-resample

f.new.vox2ras.nii.gz will have the same dimension and voxel size as f.nii.gz, but its vox2ras (sform/qform) matrix will have changed. You can check the registration in two ways:

  • The registration is created implicitly from the vox2ras matrix (that is what --regheader does). There's no need to specify and input registration
    • tkregister2 --mov f.new.vox2ras.nii.gz --s bert --regheader --reg /tmp/reg
  • Display the functional as an overlay in tkmedit (no registration needed).
    • tkmedit bert orig.mgz -overlay f.new.vox2ras.nii.gz

D. Map a binary mask in functional space to anatomical space. This is basically the same cmd line as 1.A, but --interp nearest has been added so that it does not try to interpolate the mask (ie, it will still be binary after resampling):

mri_vol2vol --reg register.dat --mov mask.nii.gz --fstarg --o mask-in-anat.mgh --interp nearest


sinc interpolation is broken except for maybe COR to COR.

See Also

mri_convert tkregister2


FreeSurfer, FsFast

Methods Description


Reporting Bugs

Report bugs to <analysis-bugs@nmr.mgh.harvard.edu>


mri_vol2vol (last edited 2017-10-04 08:29:34 by MorganFogarty)