-----------------------------------------------
 Register -- interactively register slice data
-----------------------------------------------
Register reads two series of images, a TARGET set
and a MOVEABLE set, and displays them in coronal,
sagittal, horizontal, planes.  The images in the
the TARGET buffer are fixed while the images in
the MOVEABLE buffer can be modified with a linear
transformation--which included rotation,
translation, and stretching.

The goal of register is to generate a 4x4 linear
transformation matrix (register.dat) that can be
used by other programs to paint 3D statistics
made from the MOVEABLE image set onto a 2D
surface made from the TARGET image set.

Transformations (rotations, translations,
stretchings) are applied to the MOVEABLE data set
relative to its current view.  They will be
immediately visible in other planes or other
slices of the MOVEABLE date set.  Rotations take
place around the last left-clicked point.

The image sets are compared to each other by
pressing the COMPARE button.  Once the
registration is satisfactory, it can be saved
with SAVE REG (asks before overwrite).  To go
back to the original registration, quit without
saving and restart (or use READ REG in the
extended interface).

Alignment Strategies

There are two basic alignment strategies
for functional data.

 Functional Scan => Surf Scan
 Functional Scan => Alignment Scan => Surf Scan

In the first, a single repetition from the
functional data set (typically t=0) is directly
registered to the high-resolution structurals
that were used to reconstruct the cortical
surface.  The difficulty with this is that
the functional contrast is low and reversed
relative to the hi-res T1's.

In the second strategy, a T1-weighted alignment
scan taken in the same plane as the functional
scans is first aligned to the hi-res structural
used to make the surface.  The resulting
transformation matrix is then copied onto the
register.dat file in the functional scan
directory.  A direct Functional => Subject
register can then be run to touch up the
alignment (or add shear--see below).

Aligning Two High-Resolution Data Sets

Register can also be used to manually align two
high resolution data sets prior to averaging.
There are automatic algorithms to do this.
Register can help when the two data sets were
collected on different days (perhaps as Alignment
scans), and the subject's neck, jaw, and scalp
are in a different position.

Display Parameters

The default settings for "contrast" (12.0) and
"midpoint" (0.35) increase contrast between gray
and white matter in images normalized using
mri_normalize.

The "fmov" field sets the brightness of the
MOVEABLE images.  This should be set to be
approximately the same as the TARGET image.

The "masktarg" button masks out the part of the
TARGET images that extend beyond the edge of the
MOVEABLE images volume.  This is typically used
for fine adjustments on data sets collected with
a surface coil where the MOVEABLE functional
images cover only a part of the brain and the
size change during COMPARE is distracting.

Tips

If the data sets are roughly aligned, a good
strategy is to adjust the MOVEABLE in coronal
view, change to sagittal and re-adjust, change to
horizontal and re-adjust, and so on.  Change
planes often.

It may be difficult to guess how to transform the
MOVEABLE data set is oriented very differently
than the TARGET data set (e.g., the TARGET image
is coronal but the MOVEABLE image looks like a
sideways horizontal slice).  A simple strategy
here is to transform the MOVEABLE by rotating 90
degrees around a center point, and then change to
another plane.  If the MOVEABLE still appears to
be in the wrong plane, rotate 90 degrees again
and change plane again.  Eventually you will only
need an in-plane rotation to roughly align the
data sets.

To get a shearing transformation, use a rotation
combined with stretching.  For example, rotate 30
deg, stretch vertically, rotate back 30 deg, and
finally, shrink vertically.  Don't stretch until
the data sets are well aligned.

Format of register.dat (8 lines, ASCII)

 arthur   [name in subjects database]
 3.0      [pixel size (mm) of MOVEABLE]
 4.0      [slice thickness (mm) of MOVEABLE]
 0.2      [starting brightness of MOVEABLE]
   [transformation matrix]
 9.9915e-01  2.9973e-02 -4.6041e-02  6.5897e-02
 -5.7313e-03 -7.7659e-01 -6.2997e-01 -3.5452e+01
 5.4680e-02 -6.2928e-01  7.7525e-01 -6.6141e+00
 0.0000e+00  0.0000e+00  0.0000e+00  1.0000e+00

Since the pixel size is included in the file, the
homogeneous 4x4 matrix can be directly used for
data sets with different pixel sizes.

Extended Interface

Several levels of interface are available by
typing the following commands while in the
interface window:

ctrl-F1   micro (just rotate/translate)
ctrl-F2   mini  (default, adds stretching)
ctrl-F3   macro (adds read register.dat, sagittal
                   mirror, savergb, blinktime)

Standalone Operation

Tkregister can also be run as a standalone program
from anywhere in the directory tree from the
command line:

=================================================
Usage:

  tkregister local
    [mov=cwd  targ=impliedCOR]

  tkregister local <abstargdir>
    [mov=cwd  targ=absCORdir]

  tkregister <absmovdir> <abstargdir>
    [mov=abs  targ=absCORdir]

  tkregister <subj> <movdir> <targdir>
    [mov=relCORdir  targ=relCORdir]

  tkregister -mkdefault
  tkregister -readinfo

    [often run in functional subdir]
    [reldirs in $subject/mri, composite path OK]
    [abstargdirs allow cross-subject reg]

Args:

  local       movdir is cwd
  -mkdefault  make default register.dat in cwd
  -readinfo   COR-.info => register/analyse.dat
  <subject>   in subjects database
  <movdir>    moveable (im,bshort,BRIK,brik,COR)
  <targdir>   target (COR only)

Files:

  targ image   COR images--subj db, sess align
  mov image    EPI,alignCOR,subjCOR--analyse.dat
  register.dat mov: subj,pixsz,slicethick,xform
  analyse.dat  mov: aligndir,imformat,slices,x/ysz
  edit.dat     subj/tmp/edit.dat--SEND/GOTO

Options: (at end,=movdir analyse.dat,req:abs=>abs)

  -movformat <str> (-m) movimg format (rel printf)
  -nslices <n>    (-n) num slices moveable
  -reps <n>       (-e) imgs/slice (BRIK offsets)
  -imres <x> <y>  (-i) xsize,ysize moveable images
  -regdat <file>  (-r) else default=./register.dat
  -fslice1 <mm>   (-1) funct/sess offset

Examples:

  tkregister local (str<=loc;analyse/register.dat)
  tkregister local /fspace/9904TS/mprage (CORtarg)
  tkregister /fsp/9904TS/mprage /sub/me/mri/T1
  tkregister /fsp/9904TS/eccen  /sub/me/mri/T1
  tkregister /fsp/9904TS/eccen  /sub/me/mri/mprage
  tkregister marty orig/im1 orig/im2 (str2<=str1)

