-
Notifications
You must be signed in to change notification settings - Fork 3
/
x.PreProc_BET-3D
executable file
·81 lines (68 loc) · 2.99 KB
/
x.PreProc_BET-3D
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
# x.PreProc_BET-3D
# Performs brain extraction on a 3D dataset (e.g. anatomical T1-weighted 3D dataset or SBREF image of an fMRI dataset)
# READ ME! IMPORTANT: Check the output and adjust the BET flags in this script (line 62) to ensure good brain extraction before proceeding to later analysis steps
# If the brain extraction is poor, re-run BET with different flags
# See the following for info on BET flags: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/BET/UserGuide
# You can find examples of previously successful BET flag combinations on line 65
if [ $# -ne 2 ]
then
echo "**************************************************************************************"
echo "Insufficient arguments supplied"
echo "Input 1 should be the full path to the 3D input file (no file extension - assumes nii.gz)"
echo "Input 2 should be the full path to the output directory"
echo "**************************************************************************************"
exit
fi
#define inputs
input_file=${1}
output_dir=${2}
#Check the input file exists
echo "****************************"
echo "Input file is ${input_file}"
echo "****************************"
if [ ! -f "${input_file}.nii.gz" ]
then
echo "*************************************************"
echo "Cannot locate the NIFTI input file ${input_file}"
echo "...exiting!"
echo "*************************************************"
exit
fi
#If output directory is not present, make it
if [ ! -d ${output_dir} ]
then
mkdir ${output_dir}
fi
echo "*********************************"
echo "Output directory is ${output_dir}"
echo "*********************************"
#Get the input filename without the path
anat_prefix="$(basename -- $input_file)"
#Create a symbolic link of the original dataset in the output directory
if [ ! -f "${output_dir}/${anat_prefix}_ORIG.nii.gz" ]
then
ln -s "${input_file}.nii.gz" "${output_dir}/${anat_prefix}_ORIG.nii.gz"
fi
#Run brain extraction on the T1 dataset
if [ ! -f ${output_dir}/${anat_prefix}_bet.nii.gz ]
then
echo "*****************************************************************"
echo "Running brain extraction on the ${anat_prefix}"
echo "Always check the ouput! FSL-BET settings may need to be optimized"
echo "*****************************************************************"
bet "${input_file}.nii.gz" ${output_dir}/${anat_prefix}_bet -m -R
#########################################
### Past successful flag combinations ###
# User-Dataset-Datatype: [flags]
# MCW-NeilsenBrainBH-SBREF: -m -R -f 0.4 -g -0.2
#########################################
#Open up an FSLeyes window with the BET mask and original file for user inspection
ORIG_path="${output_dir}/${anat_prefix}_ORIG.nii.gz"
mask_path="${output_dir}/${anat_prefix}_bet_mask.nii.gz"
fsleyes ${ORIG_path} ${mask_path} -cm red -a 40 &
else
echo "***************************************************"
echo "Brain extraction of ${anat_prefix} already complete"
echo "***************************************************"
fi