Skip to content
Snippets Groups Projects
remove_vols 1.41 KiB
Newer Older
Rita Nunes's avatar
Rita Nunes committed
# preprocessing for DTI images acquired at FMRIB 

Usage() {
echo "REMOVE_VOLS - Remove dodgy volumes from DTI data acquired at FMRIB "
echo ""
echo "USAGE: remove_vols <input_file> <output_file> <dodgyvols> "
echo ""
echo "example: remove_vols data data_rv 4 19 35"
echo ""
echo "Note that the first volume is 0 and not 1"
echo ""
Rita Nunes's avatar
Rita Nunes committed
}

[ "$1" = "" ] && Usage
[ "$2" = "" ] && Usage
[ "$3" = "" ] && Usage

input_file=$1
output_file=$2
current_dir=`pwd`

if [ ! `imtest $input_file` ]; then
Rita Nunes's avatar
Rita Nunes committed
    echo Cant find $input_file
    exit
fi

if [ ! -e bvals ]; then
    echo Cant find bvals
    exit
fi

if [ ! -e bvecs ]; then
    echo Cant find bvecs
    exit
fi

Matthew Webster's avatar
Matthew Webster committed
fslsplit $input_file
Rita Nunes's avatar
Rita Nunes committed

vol=0
num_vols=`expr $# - 2`
t=""
rm dodgy_vols -f
Stephen Smith's avatar
Stephen Smith committed
printf $t >dodgy_vols
Rita Nunes's avatar
Rita Nunes committed

while [ $vol -lt $num_vols ]; do
Stephen Smith's avatar
Stephen Smith committed
    printf $t>tmp1
    printf $t>tmp2
Rita Nunes's avatar
Rita Nunes committed

    v=$3
    shift
    
    if [ `imtest vol000${v}` ]; then
	imrm vol000${v}
Rita Nunes's avatar
Rita Nunes committed
    fi

    if [ `imtest vol00${v}` ]; then
	imrm vol00${v}
Rita Nunes's avatar
Rita Nunes committed
    fi
    
    echo $v > tmp1
    cat dodgy_vols tmp1 > tmp2
    cat tmp2 > dodgy_vols
Rita Nunes's avatar
Rita Nunes committed

    vol=`expr $vol + 1`
done

echo Removing dodgy volumes from bvals and bvecs
matlab -nodisplay -nojvm -nosplash 1> matlab.out1 2>&1 <<EOF
 addpath('/usr/people/dtiuser/etc/FMRIB_bvals_bvecs/');
 remove_vols('$current_dir');
 exit 
EOF
Rita Nunes's avatar
Rita Nunes committed

Rita Nunes's avatar
Rita Nunes committed
echo "Merging Volumes"
Matthew Webster's avatar
Matthew Webster committed
fslmerge -t $output_file `$FSLDIR/bin/imglob vol*`
Rita Nunes's avatar
Rita Nunes committed
rm vol* -f
rm dodgy_vols -f