Skip to content
Snippets Groups Projects
siena_flirt 2.66 KiB
#!/bin/sh

#   siena_flirt - Registration part of SIENA
#
#   Stephen Smith, FMRIB Image Analysis Group
#
#   Copyright (C) 1999-2004 University of Oxford
#
#   SHCOPYRIGHT


Usage() {
    echo "Usage: siena_flirt <input1_fileroot> <input2_fileroot>"
    exit 1
}

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

[ "$1" = "" ] && Usage
[ "$2" = "" ] && Usage
[ `${FSLDIR}/bin/imtest $1` = 0 ] && Usage
[ `${FSLDIR}/bin/imtest $2` = 0 ] && Usage
A1=`${FSLDIR}/bin/remove_ext $1`;
A2=`${FSLDIR}/bin/remove_ext $2`;


# register using brains and skulls
${FSLDIR}/bin/pairreg ${A1}_brain ${A2}_brain ${A1}_brain_skull ${A2}_brain_skull ${A2}_to_${A1}.mat
${FSLDIR}/bin/pairreg ${A2}_brain ${A1}_brain ${A2}_brain_skull ${A1}_brain_skull ${A1}_to_${A2}.mat

# replace both transforms with "average" (reduces error level AND makes system symmetric)
F=${A1}_to_${A2}.mat
B=${A2}_to_${A1}.mat
${FSLDIR}/bin/convert_xfm -matonly -concat $B -omat tmp_${F}_then_${B} $F
${FSLDIR}/bin/avscale tmp_${F}_then_${B} ${A1} > tmp_${F}_then_${B}.avscale
${FSLDIR}/bin/extracttxt Backward tmp_${F}_then_${B}.avscale 4 1 > tmp_${F}_then_${B}_halfback
${FSLDIR}/bin/convert_xfm -matonly -concat tmp_${F}_then_${B}_halfback -omat $F $F
${FSLDIR}/bin/convert_xfm -inverse -matonly -omat $B $F
/bin/rm tmp_${F}_then_${B} tmp_${F}_then_${B}.avscale tmp_${F}_then_${B}_halfback

# replace the .mat matrix that takes 2->1 with one that takes 2->halfway and one that takes 1->halfway
${FSLDIR}/bin/avscale ${A2}_to_${A1}.mat ${A1}_brain > ${A2}_to_${A1}.mat_avscale
${FSLDIR}/bin/extracttxt Forward ${A2}_to_${A1}.mat_avscale 4 1 > ${A2}_halfwayto_${A1}.mat
${FSLDIR}/bin/extracttxt Backward ${A2}_to_${A1}.mat_avscale 4 1 > ${A1}_halfwayto_${A2}.mat

# produce picture for registration evaluation
${FSLDIR}/bin/flirt -out ${A1}_halfwayto_${A2} -applyxfm -init ${A1}_halfwayto_${A2}.mat -ref ${A1} -in ${A1}_brain
${FSLDIR}/bin/flirt -out ${A2}_halfwayto_${A1} -applyxfm -init ${A2}_halfwayto_${A1}.mat -ref ${A1} -in ${A2}_brain
${FSLDIR}/bin/slicer ${A2}_halfwayto_${A1} ${A1}_halfwayto_${A2} -s 1 -x 0.4 gr${A1}${A2}a -x 0.5 gr${A1}${A2}b -x 0.6 gr${A1}${A2}c -y 0.4 gr${A1}${A2}d -y 0.5 gr${A1}${A2}e -y 0.6 gr${A1}${A2}f -z 0.4 gr${A1}${A2}g -z 0.5 gr${A1}${A2}h -z 0.6 gr${A1}${A2}i
${FSLDIR}/bin/convert -colors 100 +append gr${A1}${A2}a gr${A1}${A2}b gr${A1}${A2}c gr${A1}${A2}d gr${A1}${A2}e gr${A1}${A2}f gr${A1}${A2}g gr${A1}${A2}h gr${A1}${A2}i ${A2}_regto_${A1}.gif
/bin/rm gr${A1}${A2}a gr${A1}${A2}b gr${A1}${A2}c gr${A1}${A2}d gr${A1}${A2}e gr${A1}${A2}f gr${A1}${A2}g gr${A1}${A2}h gr${A1}${A2}i ${A2}_halfwayto_${A1}.img* ${A2}_halfwayto_${A1}.hdr* ${A1}_halfwayto_${A2}.img* ${A1}_halfwayto_${A2}.hdr*