#! /bin/tcsh -f


# mri_cvs_register
#
# Wrapper for Combined Volumetric- and Surface-based Registration (CVS)
#
# Original Author: Lilla Zollei
# Created: 10-29-2009
# Edited : 12-11-2009
# Edited : 08-10-2010: added --mpi option

set inputargs = ($argv);
set VERSION = '$Id: mri_cvs_register,v 1.4.2.2 2010/08/11 17:52:00 nicks Exp $';

set movingid = ();
set templateid = ();
#set outdir = ();
set cleanup = 1;
set nolog = 0;
set UseAseg = 1;
set PrintHelp = 0;
set OnlyStep1 = 0
set OnlyStep2 = 0
set OnlyStep3 = 0
set DoAllSteps = 1
set BothHemis = 1
set UseMpi = 0
set CleanSurfReg = 0
set CleanElReg = 0
set CleanVolReg = 0

# Parsing and checking the input arguments
if($#argv == 0) goto usage_exit;
set n = `echo $argv | egrep -e --version | wc -l`
if($n != 0) then
  echo $VERSION
  exit 0;
endif
set n = `echo $argv | egrep -e --help | wc -l`
if($n != 0) then
  set PrintHelp = 1;
  goto usage_exit;
endif

goto parse_args;
parse_args_return:
goto check_params;
check_params_return:

set StartTime = `date`;
set DateString = "`date '+%y%m%d%H%M'`"

# Setting up the default params and logging utilities 
if(! $nolog) then
  set LF = ${movingid}_to_${templateid}.mri_cvs_register.$DateString.log
  if(-e $LF) mv $LF $LF.old;
  echo ""
  echo "Log file is $LF"
  echo ""
else
  set LF = /dev/null
endif

echo "Logfile for mri_cvs_register" >> $LF
date |& tee -a $LF
echo $inputargs |& tee -a $LF
echo $VERSION |& tee -a $LF
hostname |& tee -a $LF
uname -a |& tee -a $LF

############--------------##################

# setenv LD_LIBRARY_PATH $ITK_DIR
# setenv PATH {$PATH}:/usr/pubsw/packages/petsc/current/bin

set voltype = norm
set annotfile = aparc.annot
set cvsdir =  $FREESURFER_HOME/bin
set settingsfile = $cvsdir/mri_cvs_register.settings.txt

### Creating outputdir
echo The outdir:
#if ( $outdir == ()) then
if (! $?outdir) then
  set outdir = $SUBJECTS_DIR/$movingid/cvs  
endif
echo $outdir
mkdir -p $outdir

### REGISTRATION: STEP 1: #CVS_step1.csh
###     preprocessing: to get mean and Gaussian curvature files (.H, .K) if they do not exist

if ($DoAllSteps || $OnlyStep1) then 

set movingsurfdir   = $SUBJECTS_DIR/$movingid/surf 
set templatesurfdir = $SUBJECTS_DIR/$templateid/surf

set movinglabeldir   = $SUBJECTS_DIR/$movingid/label
set templatelabeldir = $SUBJECTS_DIR/$templateid/label

if ($BothHemis) then
  if ((! -e $movingsurfdir/lh.inflated.K ) || (! -e $movingsurfdir/rh.inflated.K) || ( ! -e $movingsurfdir/lh.inflated.H) || (! -e $movingsurfdir/rh.inflated.H)) then
    echo $movingid ': at least one mean and/or Gaussian curvature file is missing (.H, .K)'
    pushd $movingsurfdir
    foreach hemi (lh rh)
      set cmd = (mris_curvature -w -distances 10 10 $hemi.inflated)
      echo $cmd |& tee -a $LF
      $cmd |& tee -a $LF
      if($status) exit 1;  
    end
    popd
  endif

  if ((! -e $templatesurfdir/lh.inflated.K ) || (! -e $templatesurfdir/rh.inflated.K) || ( ! -e $templatesurfdir/lh.inflated.H) || (! -e $templatesurfdir/rh.inflated.H)) then
    echo $templateid ': at least one mean and/or Gaussian curvature file is missing (.H, .K)'
    pushd $templatesurfdir
    foreach hemi (lh rh)
      set cmd = (mris_curvature -w -distances 10 10 $hemi.inflated)
      echo $cmd |& tee -a $LF
      $cmd |& tee -a $LF
      if($status) exit 1;  
    end
    popd
  endif
else
  set hemi = $hemiReq
  if ((! -e $movingsurfdir/$hemi.inflated.K ) || ( ! -e $movingsurfdir/$hemi.inflated.H)) then
    echo $movingid ': at least one mean and/or Gaussian curvature file is missing (.H, .K)'
    pushd $movingsurfdir
    set cmd = (mris_curvature -w -distances 10 10 $hemi.inflated)
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;  
    popd
  endif

  if ((! -e $templatesurfdir/$hemi.inflated.K ) || ( ! -e $templatesurfdir/$hemi.inflated.H) ) then
    echo $templateid ': at least one mean and/or Gaussian curvature file is missing (.H, .K)'
    pushd $templatesurfdir
    set cmd = (mris_curvature -w -distances 10 10 $hemi.inflated)
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;  
    popd
  endif

endif #BothHemis

###     spherical registration (note: this step assumes existence of
###     the ?h.aparc.annot, ?h.white and ?h.pial files)

## Check whether the necessary files in label and surf exist
if ($BothHemis) then
  foreach hemi (lh rh)
    if (!(-e $movinglabeldir/$hemi.$annotfile)) then
      echo 'ERROR: The ' $hemi '.aparc.annot file should be CREATED for subject ' $movingid ' before continuing!'
      exit 1;
    endif
  end #(hemi)
  foreach hemi (lh rh)
    foreach surf (white pial)
      if (!(-e $movingsurfdir/$hemi.$surf) ) then
        echo 'ERROR: The' $hemi '.' $surf ' file should be CREATED for subject ' $movingid ' before continuing!'
        exit 1;
      endif
    end #(surf)
  end #(hemi)
else
  if (!(-e $movinglabeldir/$hemi.$annotfile)) then
    echo 'ERROR: The ' $hemi '.aparc.annot file should be CREATED for subject ' $movingid ' before continuing!'
    exit 1;
  endif
  foreach surf (white pial)
    if (!(-e $movingsurfdir/$hemi.$surf) ) then
      echo 'ERROR: The' $hemi '.' $surf ' file should be CREATED for subject ' $movingid ' before continuing!'
      exit 1;
    endif
  end #(surf)
endif #BothHemis

## Surface-based registration
if ($BothHemis) then
  foreach hemi (lh rh)
    if (!(-e $movingsurfdir/$hemi.cvs.to$templateid.sphere.reg) || $CleanSurfReg) then
      # the spherical registration does not yet exist
      set cmd = (mris_register -1 -inflated $movingsurfdir/$hemi.sphere $templatesurfdir/$hemi.sphere $movingsurfdir/$hemi.cvs.to$templateid.sphere.reg)
      echo $cmd |& tee -a $LF
      $cmd |& tee -a $LF
      if($status) exit 1;
    endif
  end    # (hemi)
else
  if (!(-e $movingsurfdir/$hemi.cvs.to$templateid.sphere.reg) || $CleanSurfReg) then
    # the spherical registration does not yet exist
    set cmd = (mris_register -1 -inflated $movingsurfdir/$hemi.sphere $templatesurfdir/$hemi.sphere $movingsurfdir/$hemi.cvs.to$templateid.sphere.reg)
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;
  endif
endif #BothHemis

## Resampling based upon surface-based registration
if ($BothHemis) then
  foreach hemi (lh rh)
    foreach surf (white pial)
      if (!(-e $outdir/$hemi.resample.$surf) || $CleanSurfReg) then 
        set cmd = (mris_resample --atlas_reg $templatesurfdir/$hemi.sphere --annot $movinglabeldir/$hemi.$annotfile $outdir/$hemi.resample.$annotfile --subject_surf $movingsurfdir/$hemi.$surf --subject_reg $movingsurfdir/$hemi.cvs.to$templateid.sphere.reg --out $outdir/$hemi.resample.$surf)     
        echo $cmd |& tee -a $LF
        $cmd |& tee -a $LF
        if($status) exit 1;
      endif
    end  # (white, pial)
  end    # (hemi)
else
  foreach surf (white pial)
    if (!(-e $outdir/$hemi.resample.$surf) || $CleanSurfReg) then 
      set cmd = (mris_resample --atlas_reg $templatesurfdir/$hemi.sphere --annot $movinglabeldir/$hemi.$annotfile $outdir/$hemi.resample.$annotfile --subject_surf $movingsurfdir/$hemi.$surf --subject_reg $movingsurfdir/$hemi.cvs.to$templateid.sphere.reg --out $outdir/$hemi.resample.$surf)     
      echo $cmd |& tee -a $LF
      $cmd |& tee -a $LF
      if($status) exit 1;
    endif
  end  # (white, pial)
endif #BothHemis

endif # --step1

### REGISTRATION: STEP 2: # CVS_step2.csh
###     elastic registartion

setenv FREESURFER_HOME_BIN $FREESURFER_HOME/bin
setenv VOLTYPE $voltype
setenv ANNOTFILE $annotfile
setenv OUTDIR $outdir 

set mmri = $SUBJECTS_DIR/$movingid/mri/
set tmri = $SUBJECTS_DIR/$templateid/mri/

if ($DoAllSteps || $OnlyStep2) then 

## Run the elastic registration
pushd $cvsdir
if (!(-e $outdir/el_reg_to$templateid.tm3d) || $CleanElReg) then
 if ($BothHemis) then
  set cmd = (perl $cvsdir/elastic_registration_CVS.pl --fixed $templateid --moving $movingid --settings $settingsfile --exe surf2vol --pial )
  if ($UseMpi) then 
   set cmd = ($cmd --mpi)
  endif 
  echo $cmd |& tee -a $LF
  $cmd |& tee -a $LF
  if($status) exit 1;
 else
  setenv HEMI $hemiReq
  set cmd = (perl $cvsdir/elastic_registration_CVS_hemi.pl --fixed $templateid --moving $movingid --settings $settingsfile --exe surf2vol --pial )
  if ($UseMpi) then 
   set cmd = ($cmd --mpi)
  endif
  echo $cmd |& tee -a $LF
  $cmd |& tee -a $LF
  if($status) exit 1;
 endif
endif
popd

endif #--step2

if ($DoAllSteps || $OnlyStep3) then 

## Apply results of elastic registration to aseg 

grep -n out_root $settingsfile | sed 's/[0-9]:/set /' > tmp.txt
source tmp.txt
rm -f tmp.txt

set elasticmorph = ${out_root}_to$templateid.tm3d

if ($UseAseg) then 
  set voltype = aseg
  if (!(-e $outdir/${elasticmorph:r}_${voltype}.mgz) || $CleanSurfReg) then 
    set cmd = (applyMorph --template $tmri/$voltype.mgz --transform $outdir/${elasticmorph} vol $mmri/$voltype.mgz $outdir/${elasticmorph:r}_${voltype}.mgz nearest)
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;
  endif
endif


### REGISTRATION: STEP 3: # CVS_step3.csh
###     intensity-based volumetric registration
###        (UseAseg==0) only intensity-based
###        (UseAseg==1) aseg + intensity-based


if ($UseAseg) then
  set voltype = aseg
  set input = ${elasticmorph:r}  # INPUT morph from CVS_step2
  set nl_regresult = nlalign-${voltype}.m3z
  set options = (-passes 3 -z 1 -aseg -dtrans 1 -w 0 -apply 1 -sigma .25 -fixed -dt 0.25 -m 0.25 -intensity 0.0 -T $cvsdir/id.xfm )
  if !(-e $outdir/${input}_${voltype}.mgz) then 
    echo 'ERROR: What happened? The ' $outdir/${input}_${voltype}.mgz ' file does not exist!'
    exit 1;
  endif
## Run the non-linear registration based on the aseg volumes.
  if (!(-e $outdir/${nl_regresult}) || $CleanVolReg) then
    set cmd = (mri_nl_align $options $outdir/${input}_${voltype}.mgz $tmri/$voltype.mgz $outdir/${nl_regresult})
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;
  endif
  
## COMBINE the elastic and aseg nonlinear morphs and APPLY the outcome to the norm volume (for the next registration step)
  set combined = combined_elreg_$voltype.tm3d  
  set voltype  = norm
  if (!(-e $outdir/$combined) || $CleanElReg || $CleanVolReg) then
    set cmd = ( createMorph --out $outdir/$combined --template $tmri/$voltype.mgz \
                            --subject $mmri/$voltype.mgz --in gcam $outdir/${nl_regresult} \
                            morph $outdir/${input}.tm3d )  
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;
  endif
  if (!(-e $outdir/${combined:r}_${voltype}.mgz) || $CleanElReg || $CleanVolReg) then
    set cmd = ( applyMorph --template $tmri/$voltype.mgz --transform $outdir/$combined \
                           vol $mmri/${voltype}.mgz $outdir/${combined:r}_${voltype}.mgz linear )
    echo $cmd |& tee -a $LF
    $cmd |& tee -a $LF
    if($status) exit 1;
  endif
  set oldcombined = $combined
  set input = ${combined:r}_${voltype}.mgz # input from aseg registration
  set basemorph = ${combined}
endif # (aseg registration)

## Intensity-based registration; the default one. 
set prefix = ()
set voltype = norm
if ($UseAseg) then # otherwise already asigned
  set prefix = afteraseg-
else
  set input = ${elasticmorph:r}.mgz # input from CVS_step2
  set basemorph = $elasticmorph
endif 

if !(-e $outdir/${input} ) then 
  echo 'ERROR: What happened? The ' $outdir/${input} ' file does not exist!'
  exit 1;
endif

if (!(-e $outdir/nlalign-$prefix${voltype}.m3z) || $CleanVolReg) then 
  set nl_regresult = nlalign-$prefix${voltype}.m3z
  set options = (-apply 1 -z 1 -sigma 2 -dt 0.0001 -intensity 0.1 -T $cvsdir/id.xfm  )
  set cmd = (mri_nl_align $options $outdir/${input} $tmri/$voltype.mgz $outdir/${nl_regresult})
  echo $cmd |& tee -a $LF
  $cmd |& tee -a $LF
  if($status) exit 1;
endif
## COMBINE the el_reg and the aseg morphs and APPLY it to the norm volumes (next registration step)
if (!(-e $outdir/combined_elreg_$prefix$voltype.tm3d  ) || $CleanElReg || $CleanVolReg) then 
  set combined = combined_elreg_$prefix$voltype.tm3d  
  set cmd = ( createMorph --out $outdir/$combined --template $tmri/$voltype.mgz \
                          --subject $mmri/$voltype.mgz --in gcam $outdir/${nl_regresult} \
                          morph $outdir/$basemorph )  
  echo $cmd |& tee -a $LF
  $cmd |& tee -a $LF
  if($status) exit 1;
endif
## APPLY the morph to the aseg volume; just for visualization
set voltype = aseg
if (!(-e  $outdir/${combined:r}-${voltype}.mgz ) || $CleanElReg || $CleanVolReg) then 
  set cmd = ( applyMorph --template $tmri/$voltype.mgz --transform $outdir/$combined \
                         vol $mmri/$voltype.mgz $outdir/${combined:r}-${voltype}.mgz nearest )
  echo $cmd |& tee -a $LF
  $cmd |& tee -a $LF
  if($status) exit 1;
endif

if ($cleanup) then
  set cmd = ( rm -f $outdir/$oldcombined $outdir/$combined)
  echo $cmd |& tee -a $LF
  $cmd |& tee -a $LF
  if($status) exit 1;
endif

echo "To check results, run:"
echo "freeview -v $outdir/${nl_regresult:r}.mgz $tmri/norm.mgz $outdir/${combined:r}_${voltype}.mgz:colormap=lut $tmri/aseg.mgz:colormap=lut"
echo " "

endif #--step3

echo " " |& tee -a $LF
echo "Started at $StartTime " |& tee -a $LF
echo "Ended   at `date`" |& tee -a $LF
echo " " |& tee -a $LF
echo "mri_cvs_register Done" |& tee -a $LF
echo " "

exit 0;

############--------------##################
############--------------##################
parse_args:
set cmdline = ($argv);
while( $#argv != 0 )

  set flag = $argv[1]; shift;

  switch($flag)

    case "--template":
      if ( $#argv < 1) goto arg1err;
      set templateid = $argv[1]; shift;
      breaksw

    case "--mov":
      if ( $#argv < 1) goto arg1err;
      set movingid = $argv[1]; shift;
      breaksw

    case "--outdir":
      if ( $#argv < 1) goto arg1err;
      set outdir = $argv[1]; shift;
      breaksw

    case "--verbose":
      if ( $#argv < 1) goto arg1err;
      set Verbosity = $argv[1]; shift;
      breaksw

    case "--noaseg":
      set UseAseg = 0;
      breaksw

    case "--mpi":
      set UseMpi = 1;
      breaksw

    case "--nocleanup":
      set cleanup = 0;
      breaksw

    case "--cleanall":
      set CleanSurfReg = 1;
      set CleanElReg = 1;
      set CleanVolReg = 1;
      breaksw

    case "--cleansurfreg":
      set CleanSurfReg = 1;
      breaksw

    case "--cleanelreg":
      set CleanElReg = 1;
      breaksw

    case "--cleanvolreg":
      set CleanVolReg = 1;
      breaksw

    case "--step1":
      set OnlyStep1 = 1;
      set DoAllSteps = 0;
    breaksw

    case "--step2":
      set OnlyStep2 = 1;
      set DoAllSteps = 0;
    breaksw

    case "--step3":
      set OnlyStep3 = 1;
      set DoAllSteps = 0;
    breaksw
    
    case "--hemi":
      if ( $#argv < 1) goto arg1err;
      set hemiReq = $argv[1]; shift;
      set BothHemis = 0;
    breaksw

    case "--no-log":
    case "--nolog":
      set nolog = 1;
      breaksw

    case "--debug":
      set verbose = 1;
      set echo = 1;
      breaksw

    default:
      echo ERROR: Flag $flag unrecognized.
      echo $cmdline
      exit 1
      breaksw
  endsw

end

goto parse_args_return;
############--------------##################

############--------------##################
check_params:

  if($#movingid == 0) then
    echo "ERROR: must spec a moving subject id"
    exit 1;
  endif

  if($#templateid == 0) then
    echo "ERROR: must spec a template subject id"
    exit 1;
  endif

  if($templateid == $movingid) then
    echo "ERROR: the moving and the template subjects need to be different!"
    exit 1;
  endif

goto check_params_return;
############--------------##################

############--------------##################
arg1err:
  echo "ERROR: flag $flag requires one argument"
  exit 1
############--------------##################

############--------------##################
arg2err:
  echo "ERROR: flag $flag requires two arguments"
  exit 1
############--------------##################

############--------------##################
usage_exit:
  echo "USAGE: mri_cvs_register"
  echo ""
  echo "Required Arguments:";
  echo "   --mov subjid       : subjid for subject to be moved / registered"
  echo "   --template subjid  : subjid for subject to be kept fixed (template)"
  echo ""
  echo "Optional Arguments"
  echo ""
  echo "   --outdir directory : output directory where all the results are written (default is SUBJECTS_DIR/mov/cvs)"
  echo "   --noaseg       : do not use aseg volumes in the registration pipeline (default is 0)"
  echo "   --nocleanup    : do not delete temporary files (default is 0)"
  echo "   --nolog        : do not produce a log file (default is 0)"
  echo "   --step1        : only do step 1 (spherical registration)"
  echo "   --step2        : only do step 2 (elastic registration)"
  echo "   --step3        : only do step 3 (volumetric registration)"
  echo "   --mpi          : use the mpi+openmp option for the 2nd step to speed computations (default is 0)"
  echo "   --cleanall     : overwrite all CVS-related morphs that might have been computed prior to the current CVS run (default is 0)"
  echo "   --cleansurfreg : overwrite CVS-related surface registration morphs that might have been computed prior to the current CVS run (default is 0)"
  echo "   --cleanelreg   : overwrite the CVS-related elastic registration morph that might have been computed prior to the current CVS run (default is 0)"
  echo "   --cleanvolreg  : overwrite CVS-related volumetric morphs that might have been computed prior to the current CVS run (default is 0)"
  echo "   --version      : print version and exit"
  echo "   --help         : print help and exit"
  echo ""

  if($PrintHelp) \
  cat $0 | awk 'BEGIN{prt=0}{if(prt) print $0; if($1 == "BEGINHELP") prt = 1 }'

exit 1;

#---- Everything below here is printed out as part of help -----#
BEGINHELP

Registers a volume (mov) to another (template) using the CVS 
registration algorithm (Postelnicu-Zollei-Fischl, TMI09). Make sure
that SUBJECTS_DIR is properly set before calling this script!

Required Arguments:

--mov subjid

Subject id of the subject (as found in SUBJECTS_DIR) whose scan is to 
be moved in registration with that of the template. 

--template subjid

Subject id of the subject (as found in SUBJECTS_DIR) whose scan is to 
be used and the template / target for the registration. 

Optional Arguments:

--outdir 

Output directory where the resulting morphs should be written. NOTE,
the morphs require quite a lot of space so make sure that there is
enough disk space available before your analysis. The default location
for the output is: SUBJECTS_DIR/mov/cvs

--noaseg

Do not use the aseg volumes in the registration pipeline. The deafult 
value is 0.

--mpi

Use the mpi+openmp version of the elastic registration step (2nd step in CVS) in  
order to speed computations up. The deafult value is 0.

--step1, --step2, --step3

--cleanall, --cleansurfreg, --cleanelreg, --cleanvolreg

DETAILS:

The CVS registration stream consists of 3 steps: (1) surface-based registration, (2) elastic registration and (3) volumetric regsitration. By default, in the current implementation of the script, step (3) consists of two steps: (i) registration using aseg volumes and (ii) registration using intensity volumes. This combination of the non-linear volumetric registrations proved to be very robust and accurate, butthe (i) step could be eliminated if quicker execution time is required by using the "--noaseg" flag.

Relevant files that you should have in your directory (most recent on the top and the oldest in the bottom):

(a) Full CVS (with both (i) and (ii))
nlalign-afteraseg-norm.m3z : the morph resulting from (ii) of step (3) (intensity-based non-linear registration); it is NOT combined with the elastic registration morph
nlalign-afteraseg-norm.mgz : the morphed norm.mgz file; it is the final result of CVS and contains contributions from ALL registration steps (combination of the elatic morph and the two m3z files)

nlalign-aseg.m3z           : the morph resulting from (i) of step (3) (aseg-based non-linear registration); it is NOT combined with the elastic registration morph
nlalign-aseg.mgz           : the morphed aseg.mgz file; it is the result of CVS up to (i) of step (3) and contains contributions from registration steps of the elatic morph and the above m3z file

el_reg_toTEMPLATE_aseg.mgz : the elastic morph applied to aseg.mgz
el_reg_toTEMPLATE.tm3d     : the elastic morph that combines correspondences recovered in steps (1) and (2)
el_reg_toTEMPLATE.mgz      : the elastic morph applied to norm.mgz

(b) shorter version of CVS (using only (ii) in step (3) of the algorithm):

nlalign-norm.m3z           : the morph resulting from step(3) (intensity-based non-linear registration); it is NOT combined with the elastic registration morph
nlalign-norm.mgz           : the morphed norm.mgz file; it is the final result of CVS and contains contributions from ALL registration steps (combination of the elatic morph and the above m3z file)

el_reg_toTEMPLATE.tm3d     : the elastic morph that combines correspondences recovered in steps (1) and (2)
el_reg_toTEMPLATE.mgz      : the elastic morph applied to norm.mgz

If you ran the mri_cvs_registration script with the "--nocleanup" option then you will see two more files called combined*tm3d. These files take up a lot of memory so by default are deleted. They can be recreated in case the cvs morph needs to be applied to another volume at a later time.  The morphs left behind when using the "--nocleanup" option are:

(a)
el_reg_toTEMPLATE.tm3d              : the elastic morph that combines correspondences recovered in steps (1) and (2)
combined_elreg_aseg.tm3d            : the morph that combines correspondences recovered in steps (1), (2) and (3) (i)
combined_elreg_afteraseg-norm.tm3d  : the morph that combines correspondences recovered in steps (1), (2), (3) (i) and (3) (ii)
(b)
el_reg_toTEMPLATE.tm3d              : the elastic morph that combines correspondences recovered in steps (1) and (2)
combined_elreg_norm.tm3d            : the morph that combines correspondences recovered in steps (1), (2) and (3) (ii)

BUGS:

SEE ALSO:

mris_register, mri_nl_align, mris_resample 
