Skip to content
Snippets Groups Projects
siena_flow2std 2.29 KiB
Newer Older
Mark Jenkinson's avatar
Mark Jenkinson committed
#!/bin/sh

#   siena_flow2std - warp flow image into standard space
Mark Jenkinson's avatar
Mark Jenkinson committed
#
#   Stephen Smith, FMRIB Image Analysis Group
#
Stephen Smith's avatar
Stephen Smith committed
#   Copyright (C) 2002-2005 University of Oxford
Mark Jenkinson's avatar
Mark Jenkinson committed
#
#   SHCOPYRIGHT

Mark Jenkinson's avatar
Mark Jenkinson committed
Usage() {
    echo "Usage: siena_flow2std <fileroot2> <fileroot2> [-d]"
Mark Jenkinson's avatar
Mark Jenkinson committed
    echo "-d : debug (don't delete intermediate files)"
Mark Jenkinson's avatar
Mark Jenkinson committed
}

if [ _$FSLDIR = _ ] ; then
    FSLDIR=/usr/local/fsl
    export FSLDIR
fi

[ "$2" = "" ] && Usage
[ `${FSLDIR}/bin/imtest $1` = 0 ] && Usage
[ `${FSLDIR}/bin/imtest $2` = 0 ] && Usage
Stephen Smith's avatar
Stephen Smith committed
A=`${FSLDIR}/bin/remove_ext $1`
B=`${FSLDIR}/bin/remove_ext $2`
Mark Jenkinson's avatar
Mark Jenkinson committed
debug=0

for opts in $@ ; do

    if [ $opts = -d ] ; then
        debug=1
    fi

done

# register to MNI152 if not already done, and create halfway2std transform
if [ ! -f ${A}_to_std.mat ] ; then
    if [ `${FSLDIR}/bin/imtest ${A}_brain` = 0 ] ; then
Mark Jenkinson's avatar
Mark Jenkinson committed
	${FSLDIR}/bin/bet $A ${A}_brain
    fi
Stephen Smith's avatar
Stephen Smith committed
    ${FSLDIR}/bin/flirt -ref ${FSLDIR}/etc/standard/avg152T1_brain -in ${A}_brain -omat ${A}_to_std.mat -o ${A}_to_std
Mark Jenkinson's avatar
Mark Jenkinson committed
fi
${FSLDIR}/bin/convert_xfm -omat ${A}_halfwayto_${B}_inv.mat -inverse ${A}_halfwayto_${B}.mat
${FSLDIR}/bin/convert_xfm -omat ${A}_halfwayto_${B}_to_std.mat -concat ${A}_to_std.mat ${A}_halfwayto_${B}_inv.mat
Mark Jenkinson's avatar
Mark Jenkinson committed

# dilate flow image, -> standard space -> mask with ss edge image -> blur -> remask
${FSLDIR}/bin/avwmaths ${A}_to_${B}_flow -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil ${A}_to_${B}_flow_dil
Stephen Smith's avatar
Stephen Smith committed
${FSLDIR}/bin/avwmaths ${B}_to_${A}_flow -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil -dil ${A}_to_${B}_flow_dilback
${FSLDIR}/bin/avwmaths ${A}_to_${B}_flow_dil -sub ${A}_to_${B}_flow_dilback -div 2 ${A}_to_${B}_flow_dil
/bin/rm ${A}_to_${B}_flow_dilback*
${FSLDIR}/bin/flirt -in ${A}_to_${B}_flow_dil -ref ${FSLDIR}/etc/standard/avg152T1_brain -out ${A}_to_${B}_flow_to_std -applyxfm -init ${A}_halfwayto_${B}_to_std.mat
${FSLDIR}/bin/avwmaths ${A}_to_${B}_flow_to_std -mas ${FSLDIR}/etc/standard/avg152T1_edges ${A}_to_${B}_flow_to_std
${FSLDIR}/bin/ip ${A}_to_${B}_flow_to_std ${A}_to_${B}_flow_to_std 0 -s 10
${FSLDIR}/bin/avwmaths ${A}_to_${B}_flow_to_std -mas ${FSLDIR}/etc/standard/avg152T1_edges ${A}_to_${B}_flow_to_std
Mark Jenkinson's avatar
Mark Jenkinson committed

# cleanup
if [ $debug = 0 ] ; then
Stephen Smith's avatar
Stephen Smith committed
    /bin/rm -f ${A}_halfwayto_${B}_inv.mat `$FSLDIR/bin/imglob -oneperimage ${A}_brain.* ${A}_to_${B}_flow_dil.* ${A}_to_std.*`
Mark Jenkinson's avatar
Mark Jenkinson committed
fi