-------------------------------------------
 HOWTO hand pre-normalize an "orig" dataset
-------------------------------------------
In cases where the automatic normalization
results in an eroded-looking brain surface, you
may have to pre-normalize the "orig" data set by
hand, and then re-run the entire process starting
with Process Volume.

Load the orig[.mgz] Data Set

First, start up tkmedit with the "orig" data set.
You may first want to make a copy of the original
data, for example:

  cd $SUBJECTS_DIR/marty/mri
  cp -r orig orig0

    *or*

  cp -r orig.mgz orig0.mgz

tkmedit Piecewise Linear Normalization Panel

Hit F3 in the medit tools window to bring up the
extended tkmedit panel (F1 goes back to the
default view).  The new subpanel on the right
allows you to test and then apply a piecewise
linear ramp of brightness correction factors
(ffrac0-3) at four control points (lim0-3).  For
example, if you click I/S (inferior/superior
direction) and set lim2 => 145, and ffrac2 =>
1.2, this means multiply the brightness value of
pixels at inferior/superior position 145 (0-255)
by 1.2.  Thus, if the pixel value was 134 (view
pixel value in upper border of display window)
the new pixel value will be 134 * 1.2 = 161.

There are 4 control points (lim0-3, 0-255 pixel
coords) that can be applied to one of the 3 main
directions in the image: posterior/anterior,
inferior/superior, or right/left.  The correction
factors are linearly interpolated between the
control points, and remain flat beyond the first
and last control points.

Try Test Normalizations using the Back Buffer

The TEST button applies the piecewise linear ramp
to the whole data set and puts the result into
the back buffer so that you can use COMPARE to
blink between it and the original image.  If you
change any settings, and hit TEST again, it will
redo the test normalization with the new
settings.

To make the eventual effect of the normalization
more obvious, it is best to turn on WMTRUNC
(e.g., with the low limit set to 90, which is the
default for mri_wmfilter), which truncated the
image to black below 90.

A <Return> in any of the lim? or frac? entries is
the same as hitting TEST, so you quickly change
the scale factors or control points in small
steps and immediately see the effects.

For example, to brighten a dim superior sagittal
region, set one control point (e.g., lim3) to the
pixel coordinate of the top of the skull (e.g.,
around 210 -- look in the lower entry of each
pair to the right of the CORONAL, SAGITTAL and
HORIZONTAL buttons for the pixel coordinates).
Now set another control point (e.g., lim2) to the
pixel coordinate just inferior to the dimmed
region (that is, where no correction needs to be
applied, for example, around 180).  Turn on
WMTRUNC, set low=90, and gradually increase
ffrac3 above 1.0, hitting a <Return> each time in
ffrac3 to see the effects.  You can use COMPARE
to see what the truncated original looks like.

Spherical Normalization

The "sph" checkbutton toggles the state of hand
normalization done by the TEST and ALL buttons
between:

  OFF=0: a piecewise 4-control-point ramp along
  one of the major axes (above)

  ON=1: a spherical field around the current
  cursor

In the second case, the current cursor sets the
center of a spherical normalization field.  The
radius of the field is set by lim0 (directly to
the left of "lim0").  The normalization factor at
the center is set by ffrac0.  There is a linear
ramp in the normalization factor (in 3D) from the
center point to the lim0 radius (no change).  In
this state, lim1-3 and ffrac1-3 are ignored.

Apply Normalization to Input Data Set (front buffer)

Once you are satisfied with your settings, apply
them to all of the images in the front (editable)
buffer of tkedit by clicking ALL.  The images
will not yet have been saved, so if you want to
go back, quit without SAVEIMG.

Save the Normalized Images

Finally, to save the modified images into the
$SUBJECTS_DIR/marty/mri/orig directory, hit
SAVEIMG.  You should now re-run the surface
reconstruction from the beginning.

Tips

You can apply several ramps in succession in
different directions (e.g., superior/inferior,
left/right), by hitting ALL several times (after
the proper setting of lim0-3 and ffrac0-3 for
each direction have are determined in
succession).

N.B.: since ALL replaces the front (editable)
buffer images with the normalized images, hitting
ALL twice with the same settings will apply that
ramp twice.  This is in contrast to the behavior
of TEST, which applies the ramp just once and
stores (overwrites) the image into the back
buffer with the result.
