Thank you for your script
 
All the best,
Shugao

On Wed, Dec 1, 2010 at 5:19 PM, Mark Jenkinson <[log in to unmask]> wrote:
Hi,

Here's the script that will do step 1.
You just need to save the script somewhere,
make it executable (chmod 755 filename) and
then run it.  Although it isn't the most efficient
script it shouldn't take more than a minute or
two to run.

Note that some voxels contain more than one
mesh points and so these end up with values
greater than 1.  If you don't want this then run
 fslmaths imagename -bin imagename
to turn it into a purely binary image.

All the best,
       Mark




#!/bin/sh

if [ $# -lt 2 ] ; then
 echo "Usage: `basename $0` <vtk file> <output image>"
 exit 1;
fi

vtk=$1
rim=$FSLDIR/data/standard/MNI152_T1_2mm
outim=$2

line1=`grep -n POINTS $vtk`;
np=`echo $line1 | awk '{ print $2 }'`;
n1=`echo $line1 | sed 's/:.*//'`;
n2=`grep -n LOOKUP $vtk | sed 's/:.*//'`;
n1end=`echo $n1 + $np - 1 | bc`;
n2end=`echo $n2 + $np - 1 | bc`;

sed -n "${n1},${n1end}p" $vtk > FSLTMP1
sed -n "${n2},${n2end}p" $vtk > FSLTMP2

$FSLDIR/bin/fslmaths $rim -mul 0 $outim
nums=`grep -n [1-9] FSLTMP2 | sed 's/:.*//'`;
for n in $nums ; do
  echo $n : $np
  coords=`sed -n "${n}p" FSLTMP1`;
  roivals=`echo $coords | awk '{ print $1 / 2 + 0.5 " 1 " $2 / 2 + 0.5 " 1 " $3 / 2 + 0.5 " 1 0 1" }'`;
  # echo $FSLDIR/bin/fslmaths $rim -mul 0 -add 1 -roi $roivals -add $outim $outim
  $FSLDIR/bin/fslmaths $rim -mul 0 -add 1 -roi $roivals -add $outim $outim
done