-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathx.PreProc_BET-4D
executable file
·68 lines (56 loc) · 2.44 KB
/
x.PreProc_BET-4D
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
#!/bin/sh
# x.PreProc_BET-4D
# Runs brain extraction on a 4D dataset (e.g. motion corrected functional image)
if [ $# -ne 2 ]
then
echo "*****************************************************************************************************"
echo "Insufficient arguments supplied"
echo "Input 1 should be the full path to the 4D input scan (do not include 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
input_prefix="$(basename -- $input_file)"
# Run brain extraction
if [ ! -f "${output_dir}/${input_prefix}_bet.nii.gz" ]
then
echo "*****************************************************************"
echo "Running brain extraction on ${input_prefix}.nii.gz"
echo "Always check the ouput! FSL-BET settings may need to be optimized"
echo "*****************************************************************"
bet "${input_file}.nii.gz" "${output_dir}/${input_prefix}_bet.nii.gz" -m -F
#erode edges for a more conservative brain mask
echo "**************************************************"
echo "Eroding edges from ${input_prefix}_bet.nii.gz"
echo "**************************************************"
fslmaths "${output_dir}/${input_prefix}_bet_mask.nii.gz" -ero "${output_dir}/${input_prefix}_bet_mask_ero.nii.gz"
3dcalc -a "${output_dir}/${input_prefix}_bet.nii.gz" -b "${output_dir}/${input_prefix}_bet_mask_ero.nii.gz" -expr "a*b" -prefix "${output_dir}/${input_prefix}_bet_ero.nii.gz"
else
echo "**********************************************************"
echo "Brain extraction on ${input_prefix}.nii.gz already complete"
echo "**********************************************************"
fi