------------------------------------------------
 Medit -- display and edit MRI slice data
------------------------------------------------
Medit reads one or more series of images and
displays them in coronal, sagittal, horizontal,
or all 3 planes.  The images in the first (edit)
buffer can be edited and saved.  Images read into
the second buffer cannot be edited.  Edits
applied while viewing the second buffer affect
the first buffer (useful when edit buffer has
segmented white matter and second buffer has
original full T1 images).

Medit can also read in a surface and display the
intersection of the surface with the current
slice.  The interface is described from upper
left to lower right.

CORONAL/SAGITTAL/HORIZONTAL button/slider/field

 button:  switch to this view
 slider:  change coronal slice
 slider field:    enter/view slice number
 talairach field: enter/view coord (MNI software)

When switching planes, the new plane will pass
through the current location.  This is the
location of most recent left-click (default at
startup is center).

To move one slice, use the arrow keys or click in
a slider well to the left or right of a slider.

Display parameters (surface/contrast/midpoint)

The "overlay" checkbutton displays functional
data over an anatomical slice image.  The
contrast and threshold of the overlaid data is
controlled by fthr/fslope/fmid fields at the
lower middle right).  This functionality only
supports real data type (not complex data from
phase-encoded experiments) and is not as
well-developed as AFNI data overlays.  It is
accessed by the VOLUME-STATS button at the top of
the SessionTools -> View Functional Data panel.

The "surface" checkbutton toggles whether or not
the intersection of the currently-read-in surface
with the current slice is displayed.

Higher numbers in "contrast" field increase the
steepness of the sigmoid that is multiplied by
the data before display (default contrast=12.0).
The "midpoint" field sets the data number that
appears at half-max brightness.  The units are
0.0-1.0, so a midpoint setting of 0.35 (default)
means that image data that has a value of 0.35 *
255 = 89 will be displayed at half-max (=128).

To see points that you have edited to black
(actually an image value of 1, not 0), set
contrast and midpoint to:

  contrast = 200
  midpoint = 0.01

New contrast and midpoint settings won't be
visible until you change the slice or plane.

SAVEIMGS button

This button saves edited images (COR files) in
the editable buffer to a COR directory named by
the "outim" field.

The tilde (~) in the "outim" (and "surf") entry
field is an abbreviation of the path of the
current subject directory such as:

  /computer/usr2/subjects/marty

You can substitute an absolute path if you want
to save the images somewhere else.  There is no
edit undo; however, you can quit without saving.
Therefore, it is a good idea to save whenever you
are satified so far.

SEND/GOTO PNT

SEND PNT saves the current 3D location of the
cursor while GOTO PNT moves the display (in the
current slice plane view) to a previously saved
3D location (saved in either medit or surfer).
Note that GOTO PNT in medit goes to a 3D location
while GOTO on the surfer panel requires a search
(see Surfer help for details).

Edit Brush Control (rad, 3Dbrush)

The "rad" field sets the radius of the editing
brush.  The default is a one pixel brush.  At
larger radii, the brush is circular.  A radius of
1 is a useful brush size.  By default, the brush
is 2D, which means that it only affects pixels in
the current slice.  The "3Dbrush" checkbutton
toggles back and forth between a 2D and a 3D
brush.  Use the 3D brush with care since you are
editing slices you cannot see.

Editing (middle/right-click)

  LEFT-CLICK    just select a point
  MIDDLE-CLICK  set to white matter (255)
  RIGHT-CLICK   erase (set intensity to 1)

all3views

The "all3views" checkbutton toggles whether one
view is shown or whether 3 views (coronal,
sagittal, and horizontal) as well as a sagittal
maximum intensity projection is shown.  Clicking
in one of the views when "all3views" is selected
causes the other two views to go to the
corresponding point.  Clicking in the maximum
intensity projection view at the lower right
re-centers the 3 views.

3D/surface File Entries

  surf  -- path to surface
  outim -- path where edited images written
  rgb   -- SGI rgb bitmap

WMTRUNC

This button toggles whether the image is
truncated to zero below "low" and above "high".
The truncation is applied to both the editable
view as well as the second buffer if another
dataset has been loaded.  It is useful for
inspecting the images for small brightness ramps
which are often hard to see (because the human
visual system is so good at autonormalization).
It is typically turned on when using the
ramp-correction utilities of the extended
interface (F3), which allows piecewise linear
test correction ramps to be applied to the image
in the second buffer see if the segmentation is
improved before applying the ramps to the entire
data set (see below).

PLANEFILTER

This only works in the CORONAL plane.  It applies
the anisotropic wormhole filter to one slice
(this search 5x5x5 voxel volumes for planar
structures and performs a median filter in the
direction of greatest planarity).  After it has
run (which takes a few seconds), you can view the
different between the truncated and truncated and
filtered data set by using COMPARE.

Overlay display

The "fthr", "fslope", and "fmid" fields have the
same effect as the fthresh, fslope, and fmid
fields on the surfer tools panel.  The only color
scale available is the real-valued heat scale
(blue-cyan, red-yellow).

2nd imagedir field

By clicking READ, the dataset specified in "2nd
imagedir" is read into the second (non-editable)
buffer.  Successive READ's simply replace the
dataset in the non-editable buffer.  The field by
default expects a COR directory that is relative
to:

  $SUBJECTS_DIR/$subject/mri

You can also put an absolute path to a COR
directory into this field.

HISTOGRAM

Only supported on SGI.

SAGMIRR

This makes a mirror-image of the dataset
around the sagittal midline, which is defined
as the plane in the middle of the stack of
slices that are displayed when SAGITTAL is
clicked.

A more general flipping operator is
available from the tcl prompt (flip_corview_xyz),
which allows you to flip an arbitrary
direction into an arbitrary direction
starting from what is displayed in
CORNONAL view.  Thus:

  flip_corview_xyz  x  z  -y

changes the x-direction currently viewed in
CORONAL view to the x-direction in the new data
set, the y-direction in the current view into the
new z-direction, and the current z-direction (the
direction you move when y ou change CORONAL
slice) into the minus y-direction in the new data
set.  This command checks for degenerate flips.

COMPARE

This toggles between the volumes in the two
buffers.  You can edit in the second buffer view;
remember that in this case, edits are applied to
the editable buffer.

Larger F3 Interface (hand normalize)

Hitting F3 in the medit panel expands it (F2 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).  See Help -> Hand Pre-Normalize for
more details on how to use this facility.

------------------------------------------------
 Standalone Commandline and Script Operation
------------------------------------------------
tkmedit can also be run as a standalone program
from the command line (as long as SUBJECTS_DIR
and FUNCTIONALS_DIR are set) from the command
line:

Use: tkmedit name imgdir [surf] [-] [-tcl script]
     tkmedit local [-] [-tcl script]

  name: subjectdir name         (in $SUBJECTS_DIR)
imgdir: orig,T1,brain,wm,filled (in $subject/mri)
  surf: e.g., rh.smoothwm       (in $subject/surf)
  dash: disable editing

The program has an embedded tcl interpreter and
most of its functions (including some not exposed
to the medit tools interface, as well as some
that are now obselete...) can be accessed through
it, either interactively at the tcl prompt, %,
that appears in the terminal from which tkmedit
is started, or offline using a tcl script in a
file whose name follows the -tcl option.  If you
include an "exit" at the end of the tcl script,
tksurfer will quit when the script finishes.  You
can find commands available in the tcl
interpreter using "help" or "info":

  % help
  % info command flip*

Here is an example of a small command line tcl
script that reads in the data on the command
line, and then saves a flipped data set into
a new directory:

flip_corview_xyz -y x z
set abs_imstem /subjects/bill/mri/T1-new/COR-
write_images
exit

If you put the commands above into a file
flip.tcl, you could run it like this:

  tkmedit john T1 -tcl flip.tcl

There is a built-in script (mri2mpg.tcl) to make
3 mpg movies (coronal, sagittal, horizontal)
that can be accessed by typing F12 anywhere in
the medit tools interface.  It asks for slice
limits (min,max) in the three slice planes and
dumps the mpegs in $SUBJECTS_DIR/$name/mpg.

