hello again,
>i've been writing /bin/sh scripts based on *.hdr files. but i'd
>like my scripts to be v3.2-ready where possible. is it feasible
>to download these routines separately from the rest of v3.2?
i've taken the liberty of modifying mark's script and made it a
bit more generalized based on v3.1 v v3.2. i also added logic
to display (or not) informational messages. as a child of the
television age, i like visual stimuli :)
i am attaching the sh script below.
thank you,
- bettyann
#!/bin/sh
#+
# NAME: applyxfm4D.sh
# ONELINER: applies mcflirt's transforms to another 4D volume
# FACILITY: FSL / mcflirt / flirt
# LANGUAGE: bourne shell
# EXECUTABLE: yes
# USAGE: applyxfm4D.sh <infile4D> <outfile4D> <mcflirt matDir>
# AUTHOR: Mark Jenkinson <[log in to unmask]>
# CREATED: 2005-02-25
#
# ARGUMENTS:
# $1 - infile, 4D file to transform on a timepoint-by-timepoint basis
# $2 - outfie, newly transformed 4D volume
# $3 - matDir, matrix directory containing MAT_nnnn files created by
# mcflirt, eg, foo.feat/mc/mat
# $4 - doVerbose, display informational messages? [true]
#
# RETURNS: none
#
# MODIFIED: 2005-02-25
# 2005-02-25 - bettyann chodkowski - [log in to unmask]
# modified for use with FSL v3.1 which does not include functions
# remove_ext and imglob. also added $doVerbose and echo's and logic
# based on FSL version.
#
# DESCRIPTION:
# applies mcflirt's transforms to another 4D volume.
# splits infile into 3D subvolumes via avwsplit. each 3D subvolume
# is transformed via flirt using its accompanying mc/mat/MAT_nnnn htm.
# all these transformed 3D subvolumes are merged back into a 4D volume
# via avwmerge.
#
# USAGE:
# applyxfm4D.sh origVol xfmVol foo.feat/mc/mat
#-
# Apply transforms saved by mcflirt to mc/mat/MAT_nnnn files
if [ $# -lt 3 ] ; then
echo "Usage: $0 <infile4D> <outfile4D> <mat directory>"
exit 1;
fi
# which version of FSL are we running -- how to query this?
tmp=`where remove_ext`
if [ "$tmp" = '' ]; then
ver='3.1'
else
ver='3.2'
fi
# set defaults
doVerbose=1
# get rid of image name extensions (if they exist)
if [ $ver = '3.1' ]; then
infile=`basename $1 .hdr`
infile=`basename $1 .img`
outfile=`basename $2 .hdr`
outfile=`basename $2 .img`
matdir=$3
else
infile=`$FSLDIR/bin/remove_ext $1`;
outfile=`$FSLDIR/bin/remove_ext $2`;
matdir=`$FSLDIR/bin/remove_ext $3`;
fi
# doVerbose
if [ $# -gt 3 ]; then
if [ "$4" != "" ]; then doVerbose="$4"; fi
fi
# make files into full paths (if necessary)
if [ `dirname $infile` = "." ] ; then infile=`pwd`/$infile; fi
if [ `dirname $outfile` = "." ] ; then outfile=`pwd`/$outfile; fi
if [ `dirname $matdir` = "." ] ; then matdir=`pwd`/$matdir; fi
# tell me what i'm working with
if [ $doVerbose = 1 ]; then
echo "----------------------------------------------"
echo "Begin $0 at `date`"
echo " infile : $infile"
echo " outfile: $outfile"
echo " matdir : $matdir"
echo ''
fi
# create temporary directory for split/flirt/merge files
opwd=`pwd` # current/original working directory
cmd="mkdir ${outfile}_tmpdir; cd ${outfile}_tmpdir"
echo $cmd
eval $cmd
# split input 4D volume
cmd="avwsplit $infile"
if [ $doVerbose = 1 ]; then echo $cmd; fi
eval $cmd
# apply $matdir/MAT_nnnn to each split'd 3D volume
if [ $ver = '3.1' ]; then
volList=`ls vol*.hdr`
else
volList=`$FSLDIR/bin/imglob -oneperimage vol*`
fi
for fn in $volList ; do
fn=`basename $fn .hdr`
num=`echo $fn | sed 's/vol//'`;
cmd="flirt -in $fn -ref $fn -out $fn" # <inputvol> <refvol> <outputvol>
cmd="$cmd -paddingsize 1.0 -interp trilinear"
cmd="$cmd -applyxfm -init ${matdir}/MAT_${num}"
if [ $doVerbose = 1 ]; then echo $cmd; fi
eval $cmd
done
# merge transformed 3D volumes into a 4D volume
if [ $ver = '3.1' ]; then
volList=`ls vol*.hdr`
else
volList=`$FSLDIR/bin/imglob -oneperimage vol*`
fi
cmd="avwmerge -t $outfile" # concatenate in time
cmd="$cmd $volList"
if [ $doVerbose = 1 ]; then echo $cmd; fi
eval $cmd
# return to original working directory
cd $opwd
# clean up
cmd="rm -rf ${outfile}_tmpdir"
if [ $doVerbose = 1 ]; then echo $cmd; fi
eval $cmd
# done
if [ $doVerbose = 1 ]; then echo "End $0 at `date`"; fi
exit
|