'); document.write(''); function installJsMath() { jsMath.Process(document); } addInitEvent(installJsMath);

Computational Neuroimaging Laboratory Wiki

Trace: » eyetracker » top » labmeetings » top » surfrelax


|

Meta

Getting Started

Documentation

  • The code for SurfRelax can be found at:
/users/heegerlab/TFI

Initial Setup

If you want to use SurfRelax from the shared drive you can do the following.

1) Add these lines to your .cshrc.mine file.

setenv PATH ${PATH}:/share/wotan/heegerlab/TFI/macosx/bin                                            
setenv LD_LIBRARY_PATH /share/wotan/heegerlab/TFI/macosx/bin:/usr/local/fcl/lib                      
setenv TFIBINDIR /share/wotan/heegerlab/TFI/macosx/bin                                               
setenv TFIDIR /share/wotan/heegerlab/TFI/macosx                                                      
setenv TFIRC /share/wotan/heegerlab/TFI/macosx/bin/.tfirc

2) You will then need the “fink libraries”. You can get these by making a directory on your local machine:

/sw/lib

and then copy the files from

/share/wotan/heegerlab/TFI_finklibs/sw/lib

into that directory.

3) Make sure you have gawk in your path

which gawk

If not add a symlink (see instructions below in problems)

Installation problems (and fixes)

problem: dyld: Library not loaded: /sw/lib/libgnugetopt.1.dylib

You may get the following error:

dyld: Library not loaded: /sw/lib/libgnugetopt.1.dylib
  Referenced from: /share/wotan/heegerlab/TFI/macosx/bin/VolumeViewer
  Reason: image not found
Trace/BPT trap
fix

This means that you need to install the fink libraries into /sw/lib. To do this you can simply make the directory

/sw/lib

and copy the files in

/share/wotan/heegerlab/TFI_finklibs/sw/lib

into that directory. These files can also be downloaded from Jonas' website.

problem: gawk

You may get an error that you are missing the function gawk

fix

In a directory in your path, symlink gawk to awk.

ln -s /usr/bin/awk gawk

problem: dylib tixwish is missing

You may get an error when you start SurfRelax & that it can't link to the tixwish library.

fix

This is usually because you have the wrong version of fsl loaded. Make sure that your fsl is copied (the one on the webpage may not work) from someone who has a working installation. Then make sure that your environment variable DYLD_LIBRARY_PATH has fsl/lib in it.

problem: dyld: Library not loaded: /usr/X11R6/lib/libXft.1.dylib

If when you try to run a surfRelax function like surffilt from the command line, you get the following: dyld: Library not loaded: /usr/X11R6/lib/libXft.1.dylib

Referenced from: /sw/lib/libqt-mt.3.dylib
Reason: image not found

Trace/BPT trap

fix

In Leopard the library file does not seem to exist. You will need to have super-user permissions on your machine and do the following:

cd /usr/X11/lib
ln -s libXft.2.dylib libXft.1.dylib

Using surfrelax

Averaging multiple scans

Averaging several mprage scans can improve the quality of the anatomical image. Use one of the scans as the reference and align the others to it before averaging.

You may also use Farshad's script which uses FSL–but remember that FSL scripts ruin your nifti headers so make sure that you tack back on the original nifti header (Farshad does your script already do this?)

/users/heegerlab/farshad/scripts/shell/average_anat.sh
  • Seems FSL 3.3 preserves nifti header info. The output of this script seems fine. (-TL 11/14/2007)

Centering the volume

Edit the nifti header information in matlab

>> [d,h]=cbiReadNifti('fm-avg.hdr');
>> h.qform44(1:3,4) = -(h.dim(2:4)/2)+0.5;

If you are using an older version of FSL that does not handle header files correctly, use one of the original headers instead

>> [d,h]=cbiReadNifti('06+t1mprage/fm-anat+06+t1mprage.hdr');
>> h.qform44(1:3,4) = -(h.dim(2:4)/2)+0.5;

And save out the new header to disk

>> cbiWriteNiftiHeader(h, 'fm-avg.hdr');

Changing image orientation

In matlab:

cbiSwapNiftiDimensions(inputfile,outputfile)

e.g.

cbiSwapNiftiDimensions('fm-avg.hdr', 'fm-avg-reorient.hdr');

Run VolumeViewer <outputfile> from shell in order to verify the results[1]. .

  • In horizontal view, the front of the brain should be upward, the back downward, true left should be rightward and true right leftward (radiological convention).
  • Sagittal view should display the front of the head leftward, back rightward, top upward, and bottom downward.
  • Coronal view similary for up and down, and again in radiological convention (left shown on right, right shown on left)

Preprocessing

In shell

ImagePreprocess.tcl -noise 5 -wiener -x0 -1 -y0 -1 -z0 -1 -x1 -1 -y1 -1 -z1 -1  -lo 0 -lo 0 -hi 0 -pad 10  -verbose  fm-avg-reorient.hdr fm-avg-pp.hdr

(document this step in readme.txt or stage-01.csh)

Automated surface generation

You can skip this section and go to the scripting section below (recommended).

Alternatively, in shell

SurfAndRelax.tcl fm-avg-pp.img fm > stage-02.csh

and then verify and run stage-02.csh at your own risk!

Problems (and fixes)

Problem: automated surface generation scripts fail to run

On some machines (e.g. telluride) the automated surface generation scripts fail to run. The problem seems to be that some of the binary tools (which are called within those Tcl scripts) write a warning message (“TFISETUP environment variable not set - can't find TFI setup file! Using default values for environment variables…”) to the stderr. The binary tools work correctly using the default variables. However the Tcl exec command always fails (and subsequently the script is terminated) if the process writes to the standard error.

fix

This is a result of a faulty installation. To properly run SurfRelax, you can do either one of the following:

  1. set the environment variable TFISETUP to point to the TFIRC file in the TFI/bin directory
  2. create a .tfirc file in your home directory (just copy the TFIRC file and edit it as you see fit. actually the defaults aren't really used for anything useful, so just copy it)

-jonas

Another possible fix is:

  1. Get modified scripts from Farshad

Problem: SkullStrip.tcl fails

On some volumes, SkullStrip.tcl fails. For some reason, the output ( ${BN}_pp_strip.img ) is simply an outline of the brain, rather than the brain w/o the skull.

Fix

Lowering the ”-whigh” option helps fix the problem. The default is 120, but that is in the range of the fat around the skull. A value of 100 seems to work better.

Problem: distorted surface patch

Sometimes when you make a patch it will come out looking very distorted.

Fix

Create a new patch and try something smaller than the last patch. This is often due to some high degree of curvature in the patch that you made and the flattening algorithm had a hard time with it.

Problem: inflating surface doesn't work

If you run InflateSurface like:

InflateSurface.tcl -dhigh 2 jg_right_WM.off jg_right_WM_inflated.off

and get

child killed: segmentation violation
   while executing
"exec $TFIBINDIR/surfresample$TFIBINEXT -sub $DHI $IN $TMPDIR/$HIGHSUB > /dev/null 2>/dev/null"
   invoked from within
"if { !$USEOLD || ![file exists $TMPDIR/$HIGHSUB] } {
   if { $ITINT>0 } {
       if { $VERBOSE } { puts "Subsampling surface, degree $DHI..." }
       exec $TFIB..."
   (file "/share/wotan/heegerlab/TFI/macosx/bin/InflateSurface.tcl" line 75)

Fix

Try setting the dhigh value (resampling resolution value) to something lower

InflateSurface.tcl -dhigh 2 jg_right_WM.off jg_right_WM_inflated.off

Betina Ip writes that, setting -dhigh to a higher value may work better in some cases:

“I tried to work around a 'segmentation violation' error by setting the -dhigh lower to 2. The surface inflated, but the overlay WM surface did not show the gyri and sulci. However, trying a higher -dhigh of 6 worked for me, and the WM surface showed the expected map.”

mrLoadRet4 data viewing in SurfaceViewer

These instructions are for taking an overlay that is visible in mrLoadRet4 and displaying it in Jonas' SurfaceViewer. You may want to do this so that you can make a flat patch specially tailored for displaying the activity of interest.

  1. Export your overlay using mrLoadRet4 File/Export/Overlay. You will need to do this when your overlay is being displayed on the volume that was used in SurfRelax.
  2. Run SurfaceViewer
  3. Load Surface you want to display on (usually the inflated white matter surface–an .off file that should be in the surface directory).
  4. Click “Use sampling graph” and open up the gray index file that was created for the surface by surf2graph (this a .hdr/.img nifti file that should be in the Volume directory).
  5. Click Overlay 1 and select “data”
  6. Click No for Use Transformation
  7. Load the nifti (.hdr/.img) overlay file created above from mrLoadRet
  8. Select a colormap (e.g. hot)
  9. You may want to click Filter/Fill Gaps
  10. Click Draw
  11. Change the min (set to something above 0) /max values and click Draw again

You may now want to define a patch based on this map (These are standard procedures for creating flat patches in SurfRelax)

  1. Click on the center of the place you want the patch
  2. Click overlay 2 and select “Distance from current vertex”
  3. Choose a colormap (e.g. cool)
  4. Click Draw
  5. Set a max to something like 60 (the larger you make it the more you might experience inproper folding artifacts–i.e. distorted surfaces)
  6. Click Draw again
  7. Now select Edit/Insert Cuts
  8. Make a cut around the edge of the patch that you want
  9. Edit/Select Patch
  10. Click on patch and save

Now you do the usual process of making a patch into mrLoadRet readable format:

  1. FlattenSurface.tcl -save GM.off patch.off flat.off
  2. surf2graph -gmin 40 -gmax 120 -gsurface GM.off -patch flat.off -gimage strip.img -coord patch.coord WM.off
  3. in matlab: tfiSurf2Flat('patch.coord','patch.mat')

Scripting

Eli is working on a script that will run all of the stages of making surfaces with SurfRelax. The script will take as input a set of MPRAGE images in Nifti format and output a set of .off files.

If you have already done stage 1 (preprocessing), you can directly run stage 2.

# set DYLD_LIBRARY_PATH=/Users/eli/src/TFI/sw/lib/:/Users/eli/src/fsl/src/freeware/Darwin/lib/
set SUB = jg
# set -f path = (/Users/eli/src/fsl/bin $path)
# source ${FSLDIR}/etc/fslconf/fsl.csh
switch( ${1} )
   case stage1:
       ImagePreprocess.tcl -noise 5 -wiener -x0 -1 -y0 -1 -z0 -1 -x1 -1 -y1 -1 -z1 -1  -lo 0 -lo 0 -hi 0 -pad 10  -verbose ${SUB}-avg-reorient.img ${SUB}-avg-pp.img
       breaksw
   case stage2:
        FSLStripNormalize.tcl -save -verbose ${SUB}-avg-pp.img ${SUB}_pp_intcorr.img
        SkullStrip.tcl -wlow 82.5 -whigh 120.0 -blow 6.5 -wmask 150.0 -wval 40.43 -save -verbose ${SUB}_pp_intcorr.img ${SUB}_pp_strip.img
        FillWhiteMatter.tcl -csf 26.0 -lo 82.5 -hi 150.0   -save -verbose  ${SUB}_pp_strip.img ${SUB}_pp_fillmask.img
        SegmentHemispheres.tcl -clo 20.8 -wlo 79.0 -glo 40.43 -gint 45.5  -save -verbose  -mask ${SUB}_pp_fillmask.img ${SUB}_pp_strip.img ${SUB}_pp
        GenerateSurfaces.tcl -lo 86.0 -hi 150.0 -verbose  -mask ${SUB}_pp_fillmask.img -hemi ${SUB}_pp_lefthemisphere.off ${SUB}_pp_strip.img ${SUB}_left.img
        GenerateSurfaces.tcl -lo 86.0 -hi 150.0 -verbose  -mask ${SUB}_pp_fillmask.img -hemi ${SUB}_pp_righthemisphere.off ${SUB}_pp_strip.img ${SUB}_right.img
       breaksw
   case stage3:
       OptimizeSurface.tcl -verbose -hemi ${SUB}_pp_lefthemisphere.off  -anat ${SUB}_pp_strip.img -white 82.5 -gray 33.8 -save ${SUB}_left.off ${SUB}_left
       OptimizeSurface.tcl -verbose -hemi ${SUB}_pp_righthemisphere.off -anat ${SUB}_pp_strip.img -white 82.5 -gray 33.8 -save ${SUB}_right.off ${SUB}_right
       breaksw
   case stage4:
       InflateSurface.tcl -verbose -itlo 0 -itint 0 ${SUB}_right_WM.off ${SUB}_right_inf.off
       InflateSurface.tcl -verbose -dhigh 7 -itlo 0 -itint 0 ${SUB}_left_WM.off  ${SUB}_left_inf.off
       breaksw
   default:
endsw