------------------------------------------------
 The SessionsTools -> Setup Align/Funct Scans
 menu sets up the basic image parameters for
 functional and alignement scans in preparation
 for statistical analysis and rendering.
------------------------------------------------
On the left of this panel is a list of the
subdirectories in the current session.  On the
right are a set of pages--one for each scan
directory--that correspond to each functional
scan directory.  The first time you bring up this
panel, all the pages on the right of the panel
will be blank--no matter which scan directory is
selected, no parameters appear on the right.

The configure a particular directory, select it
from the list on the left (it should be marked
green) and then hit one of the buttons at the top
center of the panel to declare it to be either a
"Funct Scan Dir" or an "Align Scan Dir".

A "Funct Scan Dir" should contain one functional
scan, with multiple images/timepoints for each
slice.  An "Align Scan Dir" should contain a
T1-weighted scan taken in the same plane as the
functional scans, with one image per slice,
typically at a higher resolution than the
functional scans.

To save the current configuration of all of the
scan directories in the current session, hit Save
or Save/Close at the bottom of the panel.  You
can move between directories without losing any
configuration information as long as you do not
exit the panel.  Hitting Cancel will exit the
panel and leave the configuration in whatever
state it was when you first opened the panel.

The bottom buttons only affect the configuration
of the scan directories.  This information is
stored in an ASCII file:

  csurf.dat

which is located in the funct scripts directory:

  $FUNCTIONALS_DIR/$session/image/scripts

The Save/Close and Save buttons do not affect any
of the data files in the scan directories.

Configure and Convert the Alignment Scan

Once a directory has been declared to be an
"Align Scan Dir", the first step is to read the
header of an example file.  All the files within
the current scan directory will be present in
the "Image File:" combo box.  Select one of the
files (e.g., alignscan+orig.BRIK).  Then click
"READ HEADER" to attempt to read the parameters
from this file.  Verify that all the fields have
been filled in correctly.  Any fields that say
"-unset-" need to be set manually.

If the format of the scan is *not* an AFNI
BRIK or a bshort, you may be able to convert
it to a FreeSurfer native 1-byte COR format
by clicking the CONVERT=>COR button.  If this
doesn't work, try to convert to an AFNI brik
and read it directly.  CONVERT=>COR has not been
extensively tested.

Now click the INIT button near the bottom of the
panel to create an initial default transformation
matrix (the identity matrix).  This is equivalent
to assuming that the Align scan and the Subject
scan used to make the surface are already aligned
(they often *not* be aligned).  A panel will
say this was done automatically if you forget
when you hit the "Align=>Subj" button

Register the Alignment Scan

Now use the "Align=>Subj" button starts up the
registration program (tkregister) with the scans
used to make the surface for this subject as the
TARGET scan, and the alignment scans in the
currently selected directory as the MOVEABLE
scan.

The sole purpose of the tkregister application is
to generate a transformation matrix that maps the
alignment scan onto the scans used to make the
subject's surface.  The only file that tkregister
affects is:

  register.dat

one of which is located in each scan dir:

  $FUNCTIONALS_DIR/$session/image/$scan

See the "Register" Help menu item for tips on
how to register data sets.

Once the data sets have been aligned to your
satisfaction, hit the SAVEREG button on the
tkregister application to save it (it will backup
the previous registration matrix to the file
register.dat~).  Then quit the tkregister
application (using same now-purple button you
started it with).

Configure the Functional Scans

Now select each functional scan in the listbox at
the left and configure each one as a "Funct Scan
Dir".  Fill in any missing or "-unset-"
parameters.

Siemens UCSD mosaic note: although READ HEADER
can identify some of the parameters in a Siemens
mosaic scan, tkregister can't read a mosaic
directly.  First convert it a BRIK with thor.

Don't run the FUNCT=>SUBJ register button yet,
but be sure to open the combox box labeled
"Same-Plane Structural Dir:" at the bottom of the
panel to and select the alignment scan to be
associated with this functional scan.  This makes
it possible for there to be more than one
alignment scan.

Viewing Functional Scans

If the functional scan is a bona fide *.BRIK
file, you can view it with AFNI by typing
Alt-a in the panel (or using the AFNI button).
This will start AFNI in the currently selected
functional scan directory.

Optional 3D Volume Registration using AFNI

The AFNI tool, 3dvolreg, can be used for motion
correction using the buttons in the line labeled
"Volreg:".  The combo box labeled "Targ:" picks
the target scan.  It can be the current scan
(default) or any other scan currently configured
as a functional scan.  The field "TR:" picks the
target TR (default 10).  Clicking "CURR" aligns
all the other TR's in the current functional scan
with the target TR.  Clicking "ALL" aligns all
the TR's in every currently configured functional
scan to the target TR.

The volume-registered BRIK's are then written
back into the respective scan directories with a
"-vreg" infix.  For example:

 infile:  scandir1/scanname1+orig.BRIK
 outfile: scandir1/scanname1-vreg+orig.BRIK

 infile:  scandir2/scanname2+orig.BRIK
 outfile: scandir2/scanname2-vreg+orig.BRIK

The original BRIK's will be untouched.  The name
of the new volume-register BRIK's will be
inserted into the "Image Name Format" field in
the Setup Align/Funct scans panels.  Note that
this operation doubles the size of the functional
data in each affected scandir.

This program will only run on a bona fide *.BRIK
as an input.  To go back to the original
non-motion corrected data (or to re-run the
3dvolreg program), re-select a non-vreg'd "Image
File:" and READ HEADER.

Copy Alignment Registration to Functionals

Go back to the previously configured alignment
directory and use the "Copy Align To All Functs"
button to copy the alignscan-to-subjectscan
transformation matrix into each configured
functional scan directory.  This copies the
transformation, taking into account the fact that
the slice thickness and inplane resolution
typically differs between the alignment and
functional scans).

Block Center Offset

If the alignment scan and the functional scans
have different block centers, enter them in this
field.  This is used to modify the register.dat
file when it is copied between the alignment scan
and the functional scans.

Verify/Touch-up Functional Scan Registration

Select the first functional scan at the left.
Now register the functional scan directly to the
surface reconstruction scan using the FUNCT=>SUBJ
register button, which starts tkregister again.
Since the functional and alignment scans were
collected in the same plane, the rotation of the
functional scan will be correct.

Currently, however, the offset between the first
slice in the functional and alignment scans is
not accounted for.  To correct this, use only the
TRANSLATE buttons from tkregister.  Since the
scan has already been rotated, there will be an
x, y, and z component to the translation.  Change
planes and translate until the functional scan is
aligned.

Non-Rigid Transformations

Some of the lower-bandwidth, higher
signal-to-noise scans have additional shearing
(rhomboidal) distortion.  To correct shear you
have to use a combination of a rotation and a
scaling--a rotation alone won't work.  For
example, to correct a shear in which the left
side of the image is too high and right side to
low, do something like this:

  1) choose a rotation point near the center
  2) rotate 30 degrees to the right
  3) scale 95% in the vertical direction
  4) rotate 30 degrees to the left
  5) scale 105% in the vertical direction

Apply shear/scaling with discretion, only after
completely exhausting attempts to align the
images using translation and rotation.

Copy Registration Between Functionals

After finishing with one functional, you can copy
the final functional alignment transformation
matrix between functional scans using the CP PREV
button.  Select one scan, then a second, then hit
the button.  It will ask you to verify that you
are copying the registration matrix from the
first to the second scan.  To copy the current
functional registration to all the other
functionals, use the CP TO OTHERS button.

Vtx Normal Search Operation (for Paint)

During the PAINT process (in several different
later panels), a 3D statistic is associated with
each vertex on the surface by finding which voxel
the vertex lies within.  By entering different
values into the "mn:" (minumum) and "mx:"
(maxium) fields, a search will be performed
between those limits in increments of "step:"
size.  Possible operations (radio buttons at
right) on the set of statistics recovered in the
search are: "mx" (find largest absolute-valued
statistic along the vertex normal), "av"
(find average statistic), or "mn" find minimum
absolute-valued statistic.  There is an identical
set of controls on the Import 3D Stats panel.

Common Layout of SessionTools Panels

Most of the rest of the SessionTools panels are
arranged in a similar way.

 (1) center-top buttons that configure the
     current directory as a directory of a
     certain kind or tell the program to ignore a
     directory by Unset-ing it (a previously
     configured, then Unset directory, recovers
     its sets when re-configured)

 (2) settable parameters in the main part
     of the panel

 (3) action buttons at the top right with bold
     lettering that read the parameters you have
     set and actually perform computations that
     affect data files.  Those buttons turn
     purple during computations.

Some panels have smaller actions button in the
main body of the panels, mostly for (trying to!)
read headers.

