#### 3D smoothing and gradient calc ####
-------------------------------------------
function: (left-click SMOOTH STSATS)
  smooth_stats_3d <kernelcells> <fwhm>
-------------------------------------------
function: (left-click SMOOTHSTRUCT)
  smooth_3d <kernelcells> <fwhm>
-------------------------------------------
functions: (available from tcl script)
  smooth_3d_dx <cells> <fwhm>
  smooth_3d_dy <cells> <fwhm>
  smooth_3d_dz <cells> <fwhm>
-------------------------------------------


The SMOOTHSTRUCT or SMOOTH STATS button is only
visible on fn-F2 interface.  With just a
structural scan, SMOOTHSTRUCT appears.  If an
overlay is loaded (and lower left "overlay" is
ticked), SMOOTH STATS appears.


-------------------------------------------
function: (left-click SMOOTHSTSATS)
  smooth_stats_3d <kernelcells> <fwhm>
-------------------------------------------

Smoothing stats overlay

When a statistical overlay data set is loaded, it
is first registered to the structural dataset
using register.dat, and is then upsampled to the
resolution of the structural underlay (1x1x1 mm
or 0.5x0.5x0.5 mm) without smoothing (nearest
neighbor sampling).

The SMOOTHSTATS button performs a 3D Gaussian
smoothing (convolution) using an integer kernel
cell size set up by $kcnt (unlabeled entry to the
left of "fwhm:" label), and a full width half
maximum kernel width set by the "fwhm:" field.
This is implemented as three 1D convolution
passes.  The units of fwhm and kernel cell size
are underlay dataset pixels, which are either mm
(256x256x256 underlay) or half mm (512x512x512
underlay).

The effective kernel radius, r, resulting from
successive applications of radius r1 and r2 can
be calculated using:

  r = sqrt(r1^2 + r2^2 + ... )

For n repeated applications of the same radius
kernel, r1, that reduces to:

  r = sqrt(n) * r1

Thus, 6 clicks on SMOOTHSTATS with the default
1.5 width kernel on a default 1x1x1mm underlay
gives the following FWHM smoothing on the
overlay stats:

  1 -> 1.50 mm
  2 -> 2.12 mm
  3 -> 2.60 mm
  4 -> 3.00 mm
  5 -> 3.35 mm
  6 -> 3.67 mm

The computation time scales linearly with the
(1D) kernel cell size.

No undo (but you can re-read orig stats).

-------------------------------------------
function: (left-click SMOOTHSTRUCT)
  smooth_3d <kernelcells> <fwhm>
-------------------------------------------

Smoothing editable structural underlay

To perform a 3D Gaussian smoothing of the
structural underlay itself, hit [fn-]F2 (if
tkmedit panel not already enlarged), or unlick
"overlay" (if overlay loaded).  The name of the
smooth button now changes to "SMOOTHSTRUCT".
This operation can only be done on the editable
image (not on the "im2" image).  The units are
pixels as before.

The auto-segmentation algorithms used in
recon-all sometimes fail to segment the
cerebellum and overlying inferotemporal cortex
properly when given a single high quality
MPRAGE.  This results in erosion of parts of
inferotemporal cortex.  This can usually be
fixed by light pre-smoothing of the orig data
set in tkmedit:

   open orig.mgz data set in tkmedit
   F2 (expand tkmedit interface)
   set kernel width ("fwhm:") to 1.0 or 1.5
   SMOOTHSTRUCT
   F1 (back to small interface)
   set "im:" field to: orig1mm.mgz
   "W" button (at right)

Finally, on command line, convert back
to nifti and re-run recon-all with the
smoothed input:

   cd $SUBJECTS_DIR/<subjectname>/mri
   mri_convert orig1mm.mgz orig1mm.nii

To immediately compare to unsmoothed, you can
read the unsmoothed (orig[.mgz]) back into the
second tkmedit buffer and then use the COMPARE
button:

   im2: -> orig[.mgz]
   READ
   COMPARE (toggles between the two buffers)

To undo, alt/cmd-z in image window (or tools
window).

-------------------------------------------
functions: (available from tcl script)
  smooth_3d_dx <cells> <fwhm>
  smooth_3d_dy <cells> <fwhm>
  smooth_3d_dz <cells> <fwhm>
  smooth_3d_nn <steps>
-------------------------------------------

Calculate gradients on editable structural underlay

To calculate the image gradient of the editable
image, there are three functions to convolve with
a partial derivative of a Gaussian in the x, y,
and z directions:

  smooth_3d_dx <cells> <fwhm>
  smooth_3d_dy <cells> <fwhm>
  smooth_3d_dz <cells> <fwhm>

The results are saved in 3 internal image buffers
(gradx, grady, gradz) for use in other image
calculations.

No undo needed since editable image is put back
after calc.

Nearest neighbor smoothing on editable

There is a third rarely used smoothing function,
smooth_3d_nn, that operates on the editable
underlay.  It does a boxcar average of the center
voxel and its 26 neighbors.

To undo, alt/cmd-z in image window (or tools
window).
