-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeparcellator_DK.sh
executable file
·84 lines (62 loc) · 1.8 KB
/
deparcellator_DK.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
#!/bin/bash
set -e
#define
codedir=${HOME}/code
basedir="$(pwd -P)"
usage()
{
cat<<EOF
usage: $0 options
=============================================================================================
deparcellator_DK.sh
As deparcellator but for DK atlas
Example:
deparcellator_DK.sh parcellation.nii.gz
***Entirely based on code from Dr Rafael Romero-Garcia ('El Cunado'), University of Cambridge - Muchas Gracias Cunado!***
Written by Michael Hart, University of British Columbia, April 2021
=============================================================================================
EOF
exit 1
}
# If empty options
if [[ $1 == "" ]]; then
usage
exit 1
fi
volume=$1
outname=`basename ${volume} .nii.gz`
mkdir -p ${basedir}/${outname}_seeds
outdir=${basedir}/${outname}_seeds
nParcel=1
maxParcel=`fslstats $1 -R | awk '{print $2}'`
numParcels=`printf "%0.0f\n" $maxParcel`
echo "basedir is: ${basedir}"
echo "number of parcels is: ${numParcels}"
echo "outdir is: ${outdir}"
if [ $(imtest ${volume}) == 1 ] ;
then
echo "parcellation template is ok: ${volume}"
else
echo "Cannot locate parcellation template ${volume}. Please ensure the ${volume} dataset is in this directory -> exiting now" >&2
exit 1
fi
newID=1;
while [ ${nParcel} -le ${numParcels} ]
do
fslmaths \
${volume} \
-thr ${nParcel} \
-uthr ${nParcel} \
-bin \
${outdir}/Seg`printf %04d ${nParcel}`.nii.gz
current_parcel=${outdir}/Seg`printf %04d ${nParcel}`.nii.gz
if [ `fslstats ${current_parcel} -V | awk '{print $1}'` == 0 ]; then
echo "removing ${current_parcel} as it's empty"
rm ${current_parcel}
else
mv ${current_parcel} ${outdir}/Seg`printf %04d newID`.nii.gz
newID=$(( $newID+1 ))
echo ${newID}
fi
nParcel=$((${nParcel}+1))
done