Introduction
Sample scripts demonstrating how to produce screen-cap images from tkmedit and tksurfer.
The basic ideas:
1. A tcl script run from within tkmedit (or tksurfer) instructing it to load particular files, set up a particular view, and save images. (The tcl script needs to finish by causing tkmedit/tksurfer to quit, so that the whole operation can be run multiple times from a shell script.)
2. A shell script to launch tkmedit (or tksurfer) and tell it to run the tcl script. The shell script can do this multiple times to handle multi subjects.
3. Optional: some mechanism to view the saved image files en masse (could be just the thummbnail viewer in your file browser), maybe convert them to gif or jpg and possibly generate html pages to allow users to access them in an organized and annotated manner.
Notes:
- The following are examples only, and will need various things to be edited, such as the paths to your files and scripts, desired location for output screen-cap images and so on.
- While monkeying around with tcl scripts like this, be aware that tcl scripts can write some output to the terminal window -- highly useful for debugging or reporting progress.
tkmedit example
tcl script (images for one subject)
Produces 6 coronal and 6 axial screen-caps, showing orig, white and pial surface outlines on image selected when tkmedit was launched (eg: T1.mgz).
# tkmedit_surfposn_makeimages.tcl
set subject [GetSubjectName 0]
#set subjectdir [GetSubjectDir 0] # FS bug -- this returns path to main volume, not SubjectDir
global env
set subjectsdir $env(SUBJECTS_DIR)
set subjectdir "${subjectsdir}/${subject}"
set imagedir "$subjectdir/screencaps_surfpos"
puts "Subject : $subject"
puts "Subject Dir: $subjectdir"
#----------------------------------
# Notes
#----------------------------------
# 0 Main vertices
# 1 Inflated vertices
# 2 White vertices
# 3 Pial vertices
# 4 Orig vertices
#-------------------------------------
# Load T1.mgz to main volume -- already done by original shell command
#-------------------------------------
# Load surfaces:
#
#LoadMainSurface [0=main; 1=Aux] [filename]
puts "Load main surfaces"
LoadMainSurface 0 lh.white
LoadPialSurface 0 lh.pial
LoadOriginalSurface 0 lh.orig
puts "Load aux surfaces"
LoadMainSurface 1 rh.white
LoadPialSurface 1 rh.pial
LoadOriginalSurface 1 rh.orig
puts "SetDisplayFlags"
# SetDisplayFlag 2 1
SetDisplayFlag 4 1
SetDisplayFlag 5 1
SetDisplayFlag 6 1
SetDisplayFlag 22 1
#---------------------------
proc do_one_view {orient slicenum} {
#---------------------------
global imagedir
global subject
switch -exact -- $orient {
0 { set viewname cor }
1 { set viewname axl }
2 { set viewname sag }
}
set slicestr [format "%03d" $slicenum]
SetOrientation $orient
SetSlice $slicenum
puts "RedrawScreen"
RedrawScreen
RedrawAll
RedrawScreen
RedrawAll
RedrawScreen
RedrawAll
RedrawScreen
RedrawAll
# Use braces to avoid tcl's utterly brain-dead catenation inadequacies...
set imagepath "${imagedir}/${subject}_${viewname}_${slicestr}.tif"
puts "SaveTIFF ${imagepath}"
SaveTIFF $imagepath
}
#-----------------------------
# coronal
#-----------------------------
foreach slicenum { 95 120 150 160 170 200 } {
do_one_view 0 $slicenum
}
#-----------------------------
# axial
#-----------------------------
foreach slicenum { 120 150 160 170 180 190 } {
do_one_view 1 $slicenum
}
puts "QuitMedit"
QuitMedit
# exit(0)
#=============================================
bash shell script (to produce images for multi subjects)
Launches tkmedit and tells it to load a particular MRI volume (T1.mgz) and run the tcl script shown above.
# tkmedit_surfposn_mass_images_20070917.bash
# mass images
subjectsdir=/brain-RAID2C/freesurfer_gw/MMIL_Download/20070917/Subjects
scriptdir=/brain-RAID2C/freesurfer_gw/MMIL_Download/20070917/scripts
function onesubject() {
sbjid=$1
echo "========================================"
echo " "$sbjid
echo "========================================"
subjectdir=$subjectsdir"/FS_"$sbjid
screencapdir=$subjectdir"/screencaps_surfpos"
mkdir $screencapdir
tkmedit "FS_"$sbjid T1.mgz -tcl $scriptdir"/tkmedit_surfposn_makeimages.tcl"
}
onesubject 10419
onesubject 12009
onesubject 12378
[... etc ...]
tksurfer example
tcl script (images for one subject)
Produces screen-caps of pial and white surfaces in various orientations.
# surfparc_makeimages.tcl
set subjectsdir $home
set subjectdir "$home/$subject"
set imagedir "$subjectdir/screencaps"
puts "Subject Dir: $subjectdir"
puts "Hemi: $hemi"
#----------------------------------
# Prep
#----------------------------------
# 0 Main vertices
# 1 Inflated vertices
# 2 White vertices
# 3 Pial vertices
# 4 Orig vertices
# Supposed to load into pial vertex slots, but appears to load into main instead
# read_pial_vertex_coordinates
read_surface_vertex_set 2 white
read_surface_vertex_set 3 pial
# note: following command wants side omitted
labl_import_annotation "aparc.annot"
set rotmult 1
if {$hemi == "rh"} {
set rotmult -1
}
#---------------------------
# Iterate surfaces
#---------------------------
foreach surfix {2 3} {
set surfname "ERROR"
switch -exact -- $surfix {
2 { set surfname wh }
3 { set surfname pl }
}
#show_surf vertexSet
set_current_vertex_set $surfix
#---------------------------
# Iterate views
#---------------------------
for {set viewix0 0} {$viewix0 < 6} {incr viewix0 1} {
switch -exact -- $viewix0 {
0 { set rot 0 ; set axis a ; set viewname lat ; set zoom 1.35 }
1 { set rot 180 ; set axis y ; set viewname med ; set zoom 1.35 }
2 { set rot [expr -90 * $rotmult] ; set axis y ; set viewname ant ; set zoom 1.8 }
3 { set rot [expr 90 * $rotmult] ; set axis y ; set viewname pst ; set zoom 1.8 }
4 { set rot -90 ; set axis x ; set viewname sup ; set zoom 1.35 }
5 { set rot 90 ; set axis x ; set viewname inf ; set zoom 1.35 }
}
make_lateral_view
switch -exact -- $axis {
x { rotate_brain_x $rot }
y { rotate_brain_y $rot }
}
scale_brain $zoom
redraw
# Use braces to avoid tcl's utterly brain-dead catenation inadequacies...
set imagepath "${imagedir}/${subject}_${surfname}_${hemi}_${viewname}.tif"
save_tiff $imagepath
}
}
# will cause FS to exit
exit 0
bash shell script (to produce images for multi subjects)
Launches tksurfer and tells it to load a particular hemis and surfaces, and run the tcl script shown above.
# surfparc_mass_images_20070917.bash
# mass images
subjectsdir=/brain-RAID2C/freesurfer_gw/MMIL_Download/20070917/Subjects
scriptdir=/brain-RAID2C/freesurfer_gw/MMIL_Download/20070917/scripts
function onehemi() {
sbjid=$1
hemi=$2
subjectdir=$subjectsdir"/FS_"$sbjid
screencapdir=$subjectdir"/screencaps"
mkdir $screencapdir
tksurfer "FS_"$sbjid $hemi white -tcl $scriptdir"/surfparc_makeimages.tcl"
}
function onesubject() {
sbjid=$1
echo "========================================"
echo " "$sbjid
echo "========================================"
onehemi $sbjid lh
onehemi $sbjid rh
}
onesubject 10419
onesubject 12009
onesubject 12378
[... etc ...]
Author(s)
Graham Wideman (GrahamWideman)
