#!/bin/sh # 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 "" exit 1 } [ "$1" = "" ] && Usage [ "$2" = "" ] && Usage [ "$3" = "" ] && Usage input_file=$1 output_file=$2 current_dir=`pwd` if [ ! `imtest $input_file` ]; then 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 fslsplit $input_file vol=0 num_vols=`expr $# - 2` t="" rm dodgy_vols -f printf $t >dodgy_vols while [ $vol -lt $num_vols ]; do printf $t>tmp1 printf $t>tmp2 v=$3 shift if [ `imtest vol000${v}` ]; then imrm vol000${v} fi if [ `imtest vol00${v}` ]; then imrm vol00${v} fi echo $v > tmp1 cat dodgy_vols tmp1 > tmp2 cat tmp2 > dodgy_vols rm tmp* -f 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 rm matlab.out1 -f echo "Merging Volumes" fslmerge -t $output_file `$FSLDIR/bin/imglob vol*` rm vol* -f rm dodgy_vols -f