Skip to content
Snippets Groups Projects
Commit 7ca9af63 authored by Matthew Webster's avatar Matthew Webster
Browse files

This commit was manufactured by cvs2svn to create tag 'fsl-5_0_7'.

Sprout from master 2014-06-25 13:50:34 UTC Matthew Webster <mwebster@fmrib.ox.ac.uk> 'Removed sym-links'
Delete:
    correct_and_average
    eddy_correct
    linkbedpost
    ocmr_preproc
    regscript
    remove_vols
    replace_and_average_fmrib
    rita_uncertainty_gating
parent 2b1d7b2c
No related branches found
No related merge requests found
#!/bin/sh
# Copyright (C) 2004 University of Oxford
#
# SHCOPYRIGHT
usage()
{
echo "Usage : $0 <big4D dataset> <avg file>"
echo ""
echo " This script assumes that there are 3"
echo " separate averages of 0, 29, 0, 31, 0, 0, 0 b-values"
echo " You need to also run Make_bvecs in matlab"
echo " <artefactfile> is optional"
exit 1
}
[ $# -lt 2 ] && usage
data=`remove_ext ${1}`;
if [ `imtest $data` -eq 0 ];then
echo "Cannot find image called $1";
exit
fi
avgfile=$2;
if [ ! -e $avgfile ];then
echo " Cannot find $2"
exit
fi
numlines=`cat $avgfile |grep -v '^ *$'|wc -l`;
numavgs=`expr $numlines - 1`;
scans_per_avg=`cat $avgfile |sed 's/, *$/ /g'|sed 's/[^,]/ /g'|sed -n '1p'|wc -w`;
scans_per_avg=`expr $scans_per_avg + 1`
b0_numbers=`cat $avgfile |grep -v '^ *$' |sed -n "${numlines}p"`;
ab0=`echo $b0_numbers |awk '{print \$1}'`
eddy_correct ${1} ${$}${1}_b0_correct $ab0
total_vols=`fslval $1 dim4`;
vols_per_avg=`echo "10k $total_vols $numavgs / p"|dc -`;
fslroi ${1} data 0 ${vols_per_avg};
fslmaths data -mul 0 data;
avg=1;scan=1;
while [ ${avg} -le ${numavgs} ]; do
scan=1
#echo ${scan} ${scans_per_avg}
while [ ${scan} -le ${scans_per_avg} ]; do
tmp=`cat $avgfile |sed -n "${avg}p"|awk -F , "{ print \\$$scan }"`;
echo $avg $scan $tmp $vols_per_avg
fslroi ${$}${1}_b0_correct ${$}avg_${avg}_scan_${scan} $tmp;
scan=`expr $scan + 1`;
done
fslmerge -t ${$}avg_${avg}_all `imglob ${$}avg_${avg}_scan_*`
fslmaths data -add ${$}avg_${avg}_all data;
avg=`expr $avg + 1`;
done
fslmaths data -div ${numavgs} data;
rm ${$}*
#!/bin/sh
# Copyright (C) 2004 University of Oxford
#
# SHCOPYRIGHT
Usage() {
echo ""
echo "Usage: eddy_correct <4dinput> <4doutput> <reference_no>"
echo ""
exit 1
}
[ "$3" = "" ] && Usage
input=`${FSLDIR}/bin/remove_ext ${1}`
output=`${FSLDIR}/bin/remove_ext ${2}`
ref=${3}
if [ `${FSLDIR}/bin/imtest $input` -eq 0 ];then
echo "Input does not exist or is not in a supported format"
exit 1
fi
avwroi $input $output $ref 1
avwsplit $input
full_list=`${FSLDIR}/bin/imglob -oneperimage vol*`
for i in $full_list ; do
echo processing $i
echo processing $i >> ${output}.ecclog
${FSLDIR}/bin/flirt -in $i -ref $output -nosearch -o $i -paddingsize 1 >> ${output}.ecclog
done
avwmerge -t $output $full_list
/bin/rm vol*
#!/bin/sh
if [ $# -lt 1 ];then
echo "Usage: linkbedpost <sourcedir>"
echo ""
echo "linkbedpost /usr/people/dtiuser/OCMR/CONTROLS/2mmdata/OCMR_20_001.bedpost"
exit 1
fi
source=$1;
targ=`basename $1`
mkdir $targ
mkdir ${targ}/xfms
for i in `imglob -extension ${source}/dti_* ${source}/mean_* ${source}/merged_* ${source}/dyad* ${source}/nodif_* ${source}/nodif_* ${source}/struct* ${source}/standard*`; do
j=`basename $i`;
ln -s $i ${targ}/$j
done
for i in ${source}/xfms/*.mat;do
j=`basename $i`;
ln -s $i ${targ}/xfms/${j}
done
for i in ${source}/bv*;do
j=`basename $i`;
ln -s $i ${targ}/$j
done
#!/bin/sh
# Copyright (C) 2004 University of Oxford
#
# SHCOPYRIGHT
usage()
{
echo "Usage :ocmr_preproc <number of slices per volume>"
echo ""
exit 1
}
[ $# -lt 1 ] && usage
nep=`echo *ep2d_* |wc -w`
nlp=`echo *lp2d_* |wc -w`
if [ $nep -gt 1 ];then
a1=`imglob images_?_*ep2d_*`
a2=`imglob images_??_*ep2d_*`
fslmerge -t big4D $a1 $a2
elif [ $nlp -gt 1 ];then
a1=`imglob images_?_*lp2d_*`
a2=`imglob images_??_*lp2d_*`
fslmerge -t big4D $a1 $a2
fi
#nslices=${1}
#zsize=`fslval big4D dim3`
#tsize=`fslval big4D dim4`
#tpts=`echo "10k $zsize $nslices /p "|dc -`
#afterdot=`echo $tpts | awk -F . '{print \$2}'`
#foo=`echo $afterdot|grep [123456798]`
#if [ ! "$foo" = "" ]; then
# echo "wrong number of slices somewhere - exiting"
# exit 1
#fi
#tpts=`echo "$tpts \* $tsize" |bc"'
#xsize=`fslval big4D dim1`
#ysize=`fslval big4D dim2`
#xvoxsize=`fslval big4D pixdim1`
#yvoxsize=`fslval big4D pixdim2`
#zvoxsize=`fslval big4D pixdim3`
#datatype=`fslval big4D datatype`
#fslcreatehd $xsize $ysize $nslices $tpts $xvoxsize $yvoxsize $zvoxsize 0 0 0 0# $datatype big4D
#!/bin/sh
# preprocessing for DTI images acquired at FMRIB
####################################################################
#This script performs registration of all the volumes
#in a given dti dataset to a reference non-diffusion-weighted image
#(scaling, translation along the PE direction and shearing)
#Brain Extraction is also performed
#with a fractional intensity treshold of 0.025
####################################################################
Usage() {
echo "REGSCRIPT - Preprocessing for DTI images acquired at FMRIB "
echo ""
echo "USAGE: regscript <username> <study_number> <output_dir> [number_acqs] [type_of_correction] [series_numb_dti] [zero_pad] [study_dir]"
echo ""
echo "default number_acqs is 1"
echo ""
echo "The FID files should normally be in"
echo " ~username/scratch/MRdata/study_number/"
echo ""
echo "type_of_correction (optional):"
echo " mc - correct for eddy currents and motion (default)"
echo " bvecs will only be rotated if number_acqs is 1"
echo " as the amount of rotation corresponding to a given"
echo " volume for different acquisitions would not be the same"
echo " and it wouldn't be possible to simply average the data"
echo " ed - correct only for eddy currents (3 degrees of freedom)"
echo ""
echo "series_numb_dti (optional)- default is 2"
echo " e.g. series_2.1 - non-DW image (nodif)"
echo " series_2.2 - DTI (acquisition 1)"
echo " series_2.3 - DTI (acquisition 2) ..."
echo ""
echo "zero_pad (optional) - default is off"
echo " set it on to run load_varian"
echo " with the option -hkspad "
echo " you might wish to try this if the"
echo " half k-space reconstruction has failed"
echo ""
echo "Indicate study_dir if the files are in a different directory"
echo ""
echo "OUTPUTS"
echo "-----------------------------------------------------------------------"
echo " non-DWI: nodif"
echo " DTI after registration: data (if number_acqs equal to 1)"
echo " data1, data2... (several repetitions)"
echo " Brain mask: nodif_brain_mask"
echo " T1-structural (optional - only if series_numb_dti is 2): struct"
echo " T2-structural (optional - only if series_numb_dti is 2): T2-weighted"
echo " Diffusion directions: bvals and bvecs"
echo ""
exit 1
}
#===================================================================
correct_bvs() {
#===================================================================
# Arg_1 = fid directory - to read procpar file
fid_dir=$1
matlab -nodisplay -nojvm -nosplash 1> matlab.out1 2>&1 <<EOF
addpath('/usr/people/dtiuser/etc/FMRIB_bvals_bvecs/');
rotate_bvecs($number_acqs,$n_vols,'$fid_dir');
exit
EOF
rm matlab.out1 -f;
}
#===================================================================
[ "$1" = "" ] && Usage
[ "$2" = "" ] && Usage
[ "$3" = "" ] && Usage
username=$1
study_number=$2
output_dir=`pwd`/$3
if [ $# -ge 4 ]; then
number_acqs=$4
echo Assuming number_acqs is $number_acqs
else
number_acqs=1;
echo Assuming number_acqs is 1
fi
if [ $# -ge 5 ]; then
type_cor=$5
else
type_cor='mc'
fi
if [ $# -ge 6 ]; then
series_numb=$6
echo series_numb_dti is $series_numb
else
series_numb=2;
echo series_numb_dti is $series_numb
fi
option='-hks'
if [ $# -ge 7 ]; then
check=$7
check_option=`echo $check`
case $check_option
in
on) option='-hkspad';;
off) option='-hks';;
*) option='-hks';;
esac
fi
echo load_varian will run with option $option
if [ $# -ge 8 ]; then
study_dir=$8
else
study_dir=/usr/people/${username}/scratch/MRdata
fi
nodiffid=${study_dir}/${study_number}/series_${series_numb}.1
dtifid=${study_dir}/${study_number}/series_${series_numb}.
structfid=${study_dir}/${study_number}/series_3.1
T2fid=${study_dir}/${study_number}/series_4.1
if [ ! -e $output_dir ]; then
mkdir $output_dir
fi
cd $output_dir
echo output_dir is $output_dir
cp ~dtiuser/etc/dof3 .
#Load FID files
if [ -e ${nodiffid}.fid ]; then
echo Loading nodif
load_varian $nodiffid $output_dir/nodif -auto -float -buo $option
else
echo $nodiffid.fid: FID not found
exit;
fi
nvols_nodif=`fslval $output_dir/nodif dim4`
if [ $nvols_nodif -gt 1 ]; then
echo nodif has more than 1 volume - file name will be changed to data
echo first volume will be saved as nodif
immv nodif dti1
fslroi dti1 nodif 0 1
count=1
image_numb=2
scan_numb=2
else
count=0
image_numb=1
scan_numb=2
fi
while [ $count -lt $number_acqs ]; do
if [ -e ${dtifid}${scan_numb}.fid ]; then
echo Loading dti${image_numb}
load_varian ${dtifid}${scan_numb}.fid ${output_dir}/dti${image_numb} -auto -float -buo -egrv $option
else
echo ${dtifid}${image_numb}.fid: file not found
exit;
fi
count=`expr $count + 1`;
image_numb=`expr $image_numb + 1`;
scan_numb=`expr $scan_numb + 1`;
done
scan_numb=`expr $scan_numb - 1`;
if [ $series_numb -eq 2 ]; then
if [ -e ${structfid}.fid ]; then
echo Loading structural
load_varian ${structfid} ${output_dir}/struct -auto -float
fi
if [ -e ${T2fid}.fid ]; then
echo Loading T2-weighted
load_varian $T2fid ${output_dir}/T2_weighted -auto -float
fi
fi
#Registers each volume in dti to the reference image nodif
nvols=`fslval dti1 dim4`;
echo $nvols gradient directions
count_acqs=0
#checking if the # of slices is the same
ns_nodif=`fslval nodif dim3`;
ns_dti=`fslval dti1 dim3`;
if [ $ns_nodif != $ns_dti ]; then
rm nodif* -f
dim1=`fslval dti1 dim1`;
dim2=`fslval dti1 dim2`;
fslroi dti1 nodif 0 $dim1 0 $dim2 0 $ns_dti 0 1
fi
correc=`echo $type_cor`;
case $correc
in
mc) echo Correcting for eddy currents and motion
if [ ! -e matrices ]; then
mkdir matrices
fi
while [ $count_acqs -lt $number_acqs ]; do
tmp_acqs=`expr $count_acqs + 1`;
fslsplit dti${tmp_acqs}
if [ $nvols -lt 9 ]; then
count=0
while [ ${count} != ${nvols} ];do
echo FLIRT on volume ${count}
flirt -in vol000$count -ref nodif -out rvol000$count -nosearch -omat matrices/mat
avscale matrices/mat vol000$count >matrices/tmp
head -n 4 matrices/tmp | tail -n 3 > matrices/MAT000${count}${tmp_acqs}
count=`expr $count + 1`;
done
else
count=0
while [ $count != 10 ];do
echo FLIRT on volume ${count}
flirt -in vol000$count -ref nodif -out rvol000$count -nosearch -omat matrices/mat
avscale matrices/mat vol000$count >matrices/tmp
head -n 4 matrices/tmp | tail -n 3 > matrices/MAT000${count}${tmp_acqs}
imrm vol000${count}
count=`expr $count + 1`;
done
while [ ${count} != ${nvols} ];do
echo FLIRT on volume ${count}
flirt -in vol00${count} -ref nodif -out rvol00${count} -nosearch -omat matrices/mat
avscale matrices/mat vol00$count >matrices/tmp
head -n 4 matrices/tmp | tail -n 3 > matrices/MAT00${count}${tmp_acqs}
rm -f matrices/mat
rm -f matrices/tmp
imrm vol000${count}
count=`expr $count + 1`;
done
fi
#Clean up unecessary files
rm vol* -f
rm dti${tmp_acqs}* -f
if [ $number_acqs -eq 1 ]
then
echo creating file: data
fslmerge -t data `$FSLDIR/bin/imglob rvol0*`
else
echo creating file: data${tmp_acqs}
fslmerge -t data${tmp_acqs} `$FSLDIR/bin/imglob rvol00*`
fi
#Clean up unecessary files
rm rvol* -f
count_acqs=`expr $count_acqs + 1`;
done
rm -f matrices/mat;
rm -f matrices/tmp;;
ed) echo Correcting only for eddy currents
while [ $count_acqs -lt $number_acqs ]; do
tmp_acqs=`expr $count_acqs + 1`;
fslsplit dti${tmp_acqs}
if [ $nvols -lt 9 ]; then
count=0
while [ ${count} != ${nvols} ];do
echo FLIRT on volume ${count}
flirt -schedule dof3 -in vol000$count -ref nodif -out rvol000$count -nosearch
count=`expr $count + 1`;
done
else
count=0
while [ $count != 10 ];do
echo FLIRT on volume ${count}
flirt -schedule dof3 -in vol000$count -ref nodif -out rvol000$count -nosearch
count=`expr $count + 1`;
done
while [ ${count} != ${nvols} ];do
echo FLIRT on volume ${count}
flirt -schedule dof3 -in vol00${count} -ref nodif -out rvol00${count} -nosearch
count=`expr $count + 1`;
done
fi
#Clean up unecessary files
rm vol* -f
rm dti${tmp_acqs}* -f
if [ $number_acqs -eq 1 ]
then
echo creating file: data
fslmerge -t data `$FSLDIR/bin/imglob rvol*`
else
echo creating file: data${tmp_acqs}
echo `$FSLDIR/bin/imglob rvol*`
fslmerge -t data${tmp_acqs} `$FSLDIR/bin/imglob rvol*`
fi
#Clean up unecessary files
rm rvol* -f
count_acqs=`expr $count_acqs + 1`;
done;;
*) echo Type_of_correction must be either mc or ed
exit;;
esac
#Brain Extraction
echo BE
bet nodif mask -f 0.025 -m
immv mask_mask nodif_brain_mask
rm mask.* -f
rm dof3 -f
#Copy relevant bvals and bvecs file
n_vols=`echo $nvols`;
case $n_vols
in
7) cp ~dtiuser/etc/FMRIB_bvals_bvecs/bvals_6 bvals;
cp ~dtiuser/etc/FMRIB_bvals_bvecs/bvecs_6 bvecs;
filename='gdata7';;
13) cp ~dtiuser/etc/FMRIB_bvals_bvecs/bvals_12 bvals;
cp ~dtiuser/etc/FMRIB_bvals_bvecs/bvecs_12 bvecs;
filename='gdata13';;
63) cp ~dtiuser/etc/FMRIB_bvals_bvecs/bvals_60 bvals;
cp ~dtiuser/etc/FMRIB_bvals_bvecs/bvecs_60 bvecs;
filename='gdata63';;
*) echo 'bvals and bvecs not available for that # of directions';
exit;;
esac
#The bvecs will only be rotated for 1 acquisition
#The amount of rotation corresponding to a given volume for
#different acquisitions would be different and it wouldn't be possible
#to simply average the data
if [ $number_acqs -eq 1 ]; then
echo Rotating bvecs using matrices produced by Flirt
case $correc
in
mc)
if [ $nvols_nodif -gt 1 ]; then
fid_direc='$nodiffid';
else
fid_direc='${dtifid}${scan_numb}.fid';
fi
correct_bvs $fid_direc;;
*) exit;;
esac
fi
echo Done!
#!/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
#!/bin/sh
#averages multiple repeats and simultaneously remove dodgy volumes
#to be used after regscript - for DTI images acquired at FMRIB
Usage() {
echo ""
echo "replace_and_average_fmrib - Preprocessing for DTI images acquired at FMRIB "
echo " run after regscript to average multiple repeats"
echo ""
echo "if necessary, indicate dodgy volumes to be removed"
echo ""
echo "_________________________________________________________________________"
echo "Usage: replace_and_average_fmrib <numb_acqs> volno volno ... volno "
echo ""
echo "output file will be called data"
echo "Note that the first volume is 0 and not 1"
echo ""
echo "Example: if you want to remove vols 4 and 5 from data1"
echo " vols 10 and 19 from data2"
echo " vol 40 from data3"
echo " having acquired 3 repeats, 60 directions"
echo ""
echo " to the volumes corresponding to data2 (10 and 19)"
echo " you should add the total number of volumes in each file,"
echo " in this case 63 (= 3 non-DW + 60 direc)"
echo " 126 (= 2*63) to the ones corresponding to data3 and so on..."
echo ""
echo "you should therefore type something like - "
echo " replace_and_average_fmrib 3 4 5 73 82 166"
echo "_________________________________________________________________________"
exit 1
}
#===================================================================
rem_vols() {
#===================================================================
# Arg_1 = input_file
# Arg_2 = num_acqs
# Arg_3 ... Arg_n dodgy_vols
input_file=$1
numb_acqs=$2
shift 2
dodgy_vols=`cat dodgy_vols`
echo "removing vols $dodgy_vols"
current_dir=`pwd`
acq=1
while [ $acq -le $numb_acqs ];do
if [ ! `imtest ${input_file}${acq}` ]; then
echo Cant find $input_file
exit
fi
acq=`expr $acq + 1`;
done
if [ ! -e bvals ]; then
echo Cant find bvals
exit
fi
if [ ! -e bvecs ]; then
echo Cant find bvecs
exit
fi
nvols=`fslval ${input_file}1 dim4`;
acq=1
while [ $acq -le $numb_acqs ]; do
echo splitting $input_file$acq
fslsplit $input_file$acq
volume=0;
if [ $nvols -lt 10 ]; then
while [ $volume -lt $nvols ]; do
immmv vol000$volume vol000${volume}_${acq}
volume=`expr $volume + 1`
done
else
volume=0
while [ $volume -lt 10 ]; do
immv vol000${volume} vol000${volume}_${acq}
volume=`expr $volume + 1`
done
while [ $volume -lt $nvols ]; do
immv vol00${volume} vol000${volume}_${acq}
volume=`expr $volume + 1`
done
fi
acq=`expr $acq + 1`;
done
vol=0
num_dodgy_vols=`expr $#`
while [ $vol -lt $num_dodgy_vols ]; do
v=$1
shift
if [ `imtest vol000${v}_1` ]; then
rm vol000${v}_* -f
fi
if [ `imtest vol00${v}_1` ]; then
rm vol00${v}_* -f
fi
vol=`expr $vol + 1`
done
acq=1
while [ $acq -le $numb_acqs ]; do
rm ${input_file}${acq}* -f
fslmerge -t data$acq `$FSLDIR/bin/imglob vol*_$acq.*`
acq=`expr $acq + 1`;
done
matlab -nodisplay -nojvm -nosplash 1> matlab.out1 2>&1 <<EOF
addpath('/usr/people/dtiuser/etc/FMRIB_bvals_bvecs/')
remove_vols('$current_dir')
EOF
rm matlab.out1 -f
rm vol0* -f
}
#===================================================================
check_vols() {
#===================================================================
# Arg_1 = n_vols
# Arg_2 = num_acqs
n_vols=$1
numb_acqs=$2
matlab -nodisplay -nojvm -nosplash 1> matlab.out1 2>&1 <<EOF
addpath('/usr/people/dtiuser/etc/FMRIB_bvals_bvecs/')
check_vols($n_vols,$numb_acqs)
EOF
rm matlab.out1 -f
}
#===================================================================
[ "$1" = "" ] && Usage
numb_acqs=$1
if [ $# -gt 1 ]; then
shift 1
if [ $numb_acqs -lt 2 ]; then
echo "replacevols_fmrib should be used when several repeats were acquired"
echo "use remove_vols instead if you want to remove dodgy volumes from single datasets"
fi
printf ""> vol_list
for i in $@ ; do
vol=$i
printf "$vol " >> vol_list
shift
done
nvols=`fslval data1 dim4`;
n_vols=`echo $nvols`
dodgy_volumes=`cat vol_list`
echo dodgy volumes: $dodgy_volumes
check_vols $n_vols $numb_acqs
if [ -e dodgy_vols ]; then
dodgy=`cat dodgy_vols`
rem_vols data $numb_acqs $dodgy
else
echo No volumes need to be removed
fi
nvols=`fslval data1 dim4`;
echo output will have $nvols volumes
dodgy_volumes=`cat vol_list`
dodgy_volumes=`echo $dodgy_volumes`
if [ -e dodgy_vols ]; then
if [ "$dodgy_volumes" != "" ]; then
echo dogdy volumes updated taking into account removed volumes
echo dodgy volumes are now: $dodgy_volumes
fi
fi
if [ "$dodgy_volumes" != "" ]; then
acq=1
echo "">file_list
while [ $acq -le $numb_acqs ];do
echo data$acq >> file_list
acq=`expr $acq + 1`;
done
file_list=`cat file_list`
fslmerge -t bigdata $file_list
rm file_list -f
echo "0 $nvols" >average_file
acq=1
first=0
second=$nvols
while [ $acq -lt $numb_acqs ];do
first=`expr $first + $nvols`;
echo "$first $second">>average_file;
acq=`expr $acq + 1`;
done
echo "">>average_file
acq=0
n_vols=`echo $nvols`
if [ $n_vols -lt 63 ]; then
b0=0;
while [ $acq -lt $numb_acqs ];do
printf "$b0 " >> average_file
acq=`expr $acq + 1`;
b0=`expr $b0 + $n_vols`;
done;
else
b0=0;b0_1=1;b0_2=2;echo ""
while [ $acq -lt $numb_acqs ]; do
printf "$b0 $b0_1 $b0_2 " >> average_file
acq=`expr $acq + 1`;
b0=`expr $b0 + $n_vols`;
b0_1=`expr $b0_1 + $n_vols`;
b0_2=`expr $b0_2 + $n_vols`;
done;
fi
if [ $FSLOUTPUTTYPE != 'ANALYZE' ]; then
fslchfiletype ANALYZE bigdata
rm bigdata.nii.gz -f
fi
replacevols bigdata average_file $dodgy_volumes tmp_file
if [ -e tmp_file.img.gz ]; then
gunzip tmp_file.img.gz
if [ -e tmp_file.hdr.gz ]; then
gunzip tmp_file.hdr.gz
fi
fi
if [ $FSLOUTPUTTYPE != 'ANALYZE' ]; then
fslchfiletype $FSLOUTPUTTYPE tmp_file
fi
nvols=`fslval tmp_file dim4`;
n_vols=`echo $nvols`
volsacqs=`fslval data1 dim4`;
vols_per_acqs=`echo $volsacqs`;
rm bigdata* -f
fslroi tmp_file data 0 ${vols_per_acqs};
fslmaths data -mul 0 data;
acq=0;
while [ ${acq} -lt ${numb_acqs} ]; do
vol=0
while [ ${vol} -lt ${vols_per_acqs} ]; do
v_tmp=`expr $vol + ${vols_per_acqs} \* ${acq}`
if [ $vol -lt 10 ]; then
fslroi tmp_file vol${acq}_000${vol} $v_tmp 1;
else
fslroi tmp_file vol${acq}_00${vol} $v_tmp 1;
fi
vol=`expr $vol + 1`;
done
fslmerge -t data${acq}_all `$FSLDIR/bin/imglob vol${acq}_*`
fslmaths data${acq}_all -div ${numb_acqs} data${acq}_all;
fslmaths data -add data${acq}_all data;
rm data${acq}_all* vol${acq}* -f
acq=`expr $acq + 1`;
done
rm *_all* -f
rm tmp* -f
rm average_file -f
else
echo averaging the data
volsacqs=`fslval data1 dim4`;
vols_per_acqs=`echo $volsacqs`;
fslroi data1 data 0 ${vols_per_acqs};
fslmaths data -mul 0 data;
acq=1;
while [ ${acq} -le ${numb_acqs} ]; do
fslmaths data${acq} -div ${numb_acqs} data${acq};
fslmaths data -add data${acq} data;
acq=`expr $acq + 1`;
done
fi
rm dodgy_vols -f
rm vol_list -f
rm vol*_* -f
else
echo no dodgy volumes
echo averaging the data
volsacqs=`fslval data1 dim4`;
vols_per_acqs=`echo $volsacqs`;
fslroi data1 data 0 ${vols_per_acqs};
fslmaths data -mul 0 data;
acq=1;
while [ ${acq} -le ${numb_acqs} ]; do
fslmaths data${acq} -div ${numb_acqs} data${acq};
fslmaths data -add data${acq} data;
acq=`expr $acq + 1`;
done
fi
echo extracting nodif image from averaged data
fslroi data nodif 0 1
rm tmp* -f
rm vol* -f
#!/usr/local/bin/bash
main_dir='/home/fs10/dtiuser/RITA/gating'
for direc in 03Aug04_SL
do
cd $direc
for a in 13
do
#fslroi data1 gated_$a 0 128 0 128 $a 1
# fslroi data2 notgated_$a 0 128 0 128 $a 1
diffmodmhgibbs -k notgated_${a} -o gated_$a -m mask_sl$a -r bvecs -b bvals -B 1000 -S 20200 --saverat=20 --scj --noprec;
# diffmodmhgibbs -k notgated_${a} -o notgated_$a -m mask_sl$a -r bvecs -b bvals -B 1000 -S 20200 --saverat=20 --scj;
done
cd $main_dir
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment