-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.sh
94 lines (79 loc) · 2.27 KB
/
preprocess.sh
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
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
if ! command -v mri_watershed &> /dev/null
then
echo "mri_watershed command not found. Please make sure FreeSurfer is installed and set up correctly."
exit 1
fi
if ! command -v N4BiasFieldCorrection &> /dev/null
then
echo "N4BiasFieldCorrection command not found. Please make sure ANTs is installed and set up correctly."
exit 1
fi
args=()
# Threads to use
threads=1
usage() {
echo
echo "Preprocess an image for pituitary segmentation."
echo
echo "Usage: $0 <input> [-h]"
echo
echo "Options:"
echo " <input> Input image filename."
echo " -h Display this help message."
echo
echo "------------------------------------------------------------"
echo "Script written by:"
echo "------------------------------------------------------------"
echo "Kaibo Tang"
echo "Department of Radiology and Biomedical Research Imaging Center (BRIC)"
echo "University of North Carolina at Chapel Hill"
echo "Contact: [email protected]"
echo "------------------------------------------------------------"
echo
exit 0
}
if [ "$#" -lt 2 ]
then
usage
fi
while [ $OPTIND -le "$#" ]
do
if getopts h option
then
case $option
in
h) usage;;
esac
else
args+=("${!OPTIND}")
((OPTIND++))
fi
done
input="${args[0]}"
if [ ! -f "$input" ]
then
echo "Input file $input not found. Exiting..."
exit 1
fi
if [ "$threads" -lt 1 ]
then
echo "Number of threads must be at least 1. Exiting..."
exit 1
fi
echo "============================================================"
echo "Input: $input"
echo "============================================================"
# Skull stripping
echo "Skull stripping $input..."
time mri_watershed -atlas "$input" "${input%.nii.gz}_strip.nii.gz" > /dev/null
echo
echo "Done skull stripping $input."
echo "------------------------------------------------------------"
input="${input%.nii.gz}_strip.nii.gz"
# N4 bias field correction
echo "Applying N4 bias correction to $input..."
time N4BiasFieldCorrection -d 3 -i "$input" -o "${input%.nii.gz}_n4.nii.gz" > /dev/null
echo
echo "Done N4 bias correction on $input."
echo "------------------------------------------------------------"