This file is indexed.

/usr/lib/voxbo/bin/spm8_segment is in voxbo 1.8.5~svn1246-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# run SPM8 unified segmentation
# TODO:
#  accept bounding box argument

# see spm_preproc.m
# see spm_preproc_write.m

if [[ "$MATLABPATH" =~ spm8 && -z "$SPM8PATH" ]] ; then SPM8PATH="$MATLABPATH"; fi
if [[ -z "$SPM8PATH" && -r /etc/voxbo/setpaths.sh ]] ; then . /etc/voxbo/setpaths.sh; fi
if [[ -z "$SPM8PATH" && -d /usr/local/spm8 ]] ; then SPM8PATH=/usr/local/spm8; fi
if [[ -z "$SPM8PATH" && -d /usr/lib/spm8 ]] ; then SPM8PATH=/usr/share/matlab/site/m/spm8; fi
if [[ -z "$SPM8CMD" && -r /etc/voxbo/setpaths.sh ]] ; then . /etc/voxbo/setpaths.sh; fi
if [[ -z "$SPM8CMD" ]] ; then SPM8CMD='matlab -nodesktop -nosplash -nojvm'; fi

# defaults
MATLABPATH=$SPM8PATH
SPM8_MATLAB_CMD=$SPM8CMD  # formerly "/usr/local/bin/matlab2009b -nodesktop -nosplash -nojvm"
PARAMFILE='seg.mat'
INFILE='mprage.nii'
OUTFILE=
TDIR="/usr/local/spm8/tpm"

printhelp() {
  echo "  "
  echo "VoxBo spm8_segment script"
  echo "summary: script for running SPM8 unified segmentation"
  echo "usage:"
  echo "  spm8_segment <flags>"
  echo "the following flags are honored:"
  echo "  -p <file>   parameter file to write (default: seg.mat)"
  echo "  -o <file>   normalized file to write (default: wmprage.nii)"
  echo "  -t <dir>    dir containing template (default: /usr/local/spm8/tpm)"
  echo "  -i <file>   3D volume to segment"
  echo "  -h          print this help"
  echo "notes:"
  echo "  This script uses SPM8's unified segmentation to calculate a warp"
  echo "  from your volume to the template included with SPM8."
  echo "  "
  echo "  Note that the template is segmented, and composed of three files:"
  echo "  gray.nii, white.nii, and csf.nii"
  echo "  "
  echo "  SPM8 handles uncompressed NIfTI files."
  echo "  "
}

if [[ $# -lt 2 ]] ; then
  printhelp;
  exit;
fi

while getopts ho:p:i: opt; do
  case "$opt" in
    h) printhelp; exit;  ;;
    i) INFILE=$OPTARG ;;
    o) OUTFILE=$OPTARG ;;
    t) TDIR=$OPTARG ;;
    p) PARAMFILE=$OPTARG ;;
    \\?) echo "argh!" ;;
  esac
done

DIR=`dirname $INFILE`
FNAME=`basename $INFILE`

echo "+---------------------------------------+"
echo "| SPM8 unified segmentation bash script |"
echo "+---------------------------------------+"
echo " infile: " $INFILE
if [[ -n $OUTFILE ]] ; then
  echo "outfile: " $OUTFILE
else
  echo "outfile: " $DIR/w$FNAME
fi
echo " params: " $PARAMFILE

$SPM8_MATLAB_CMD << EOF
spm_defaults;
global defaults;

opts0.tpm=char('$TDIR/grey.nii','$TDIR/white.nii','$TDIR/csf.nii');
opts0.ngaus    = [2 2 2 4];
opts0.warpreg  = 1;
opts0.warpco   = 25;
opts0.biasreg  = 0.0001;
opts0.biasfwhm = 60;
opts0.regtype  = 'mni';
opts0.fudge    = 5;
opts0.samp     = 3;
opts0.msk      = '';
opts1.biascor=1;
opts1.cleanup=0;
% three parts of GM/WM/CSF arg are for: native, modulated, unmodulated
opts1.GM=[0 0 1];   
opts1.WM=[0 0 1];
opts1.CSF=[0 0 1];

P=spm_vol('$INFILE')
res=spm_preproc(P,opts0)
[p,ip]=spm_prep2sn(res)

% save the forward params
fn = fieldnames(p);
for i=1:length(fn),
    eval([fn{i} '= p.' fn{i} ';']);
end;
save('$PARAMFILE',fn{:});

% in case i want the inverse params later
fn = fieldnames(ip);
for i=1:length(fn),
    eval([fn{i} '= ip.' fn{i} ';']);
end;
save('seg_inv_sn.mat',fn{:});

% write the segmented and bias corrected files
spm_preproc_write(p,opts1)

% now warp it
opts3.bb=[Inf];   % means to use template bb
opts3.vox=[1 1 1];
opts3.wrap=[0 0 0];
spm_write_sn('$INFILE',p,opts3)

EOF

echo

if [[ ! -f $DIR/w$FNAME ]] ; then exit 1 ; fi

if [[ -n $OUTFILE ]] ; then
  mv $DIR/w$FNAME $OUTFILE
  mv $DIR/w${FNAME%.*}.mat ${OUTFILE%.*}.mat
fi

exit 0