-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathx.PreProc_Mask-4D
executable file
·64 lines (54 loc) · 1.93 KB
/
x.PreProc_Mask-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
#!/bin/sh
# x.PreProc_Mask-4D
# Applies a mask to an image
# This is useful if you want to run BET on one image and apply the mask to other images in the same space.
if [ $# -ne 3 ]
then
echo "*****************************************************************************************************"
echo "Insufficient arguments supplied"
echo "Input 1 should be the full path to the input scan to be masked*"
echo "Input 2 should be the full path to the mask*"
echo "Input 3 should be the full path to the output directory"
echo "*Note: do not include file extension - assumes nii.gz"
echo "*****************************************************************************************************"
exit
fi
#define inputs
input_file=${1}
mask_file=${2}
output_dir=${3}
#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)"
# Apply mask
if [ ! -f "${output_dir}/${input_prefix}_brain.nii.gz" ]
then
echo "*************************************"
echo "Appling mask to ${input_prefix}.nii.gz"
echo "*************************************"
3dcalc -a ${input_file}.nii.gz -b ${mask_file}.nii.gz[0] \
-expr "a*b" -prefix ${output_dir}/${input_prefix}_brain.nii.gz
else
echo "****************************************"
echo "${input_prefix}_brain.nii.gz already made"
echo "****************************************"
fi