Newer
Older
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
###### START ###############
# Denote path to manual labels and auto labels, and an output path
pathManual=$1
pathAuto=$2
subj=$3
pathT1=$pathAuto
##### Calculate_FN_FP ########
# Input variables
hemisphere=(L R)
error=(FN FP)
for dir in $pathAuto/$subj; do
for h in "${hemisphere[@]}"; do
inputManual="${pathManual}/${dir##*/}/${dir##*/}_${h}hpc_mask.nii.gz"
inputAuto="${pathAuto}/${dir##*/}/T1_orig_${h}_hippocampus_ToBrain_binarised.nii.gz" #change file naming convention per method
# Check if automatic segmentation file exists
if [ -f "$inputAuto" ]; then
# Calculate false negatives and false positives
fslmaths "$inputManual" -sub "$inputAuto" -bin "${pathAuto}/${dir##*/}/${dir##*/}_${h}_FN.nii.gz"
fslmaths "$inputAuto" -sub "$inputManual" -bin "${pathAuto}/${dir##*/}/${dir##*/}_${h}_FP.nii.gz"
else
echo "Error: $inputAuto doesn't exist, skipping it"
fi
done
done
###### BET ###########
# Brain extract the original T1 for use in FLIRT
#for dir in "$pathT1"/$subj; do
# bet $pathT1/${dir##*/}/tool2raw.nii.gz $pathT1/${dir##*/}/${dir##*/}_brain.nii.gz -f 0.5 -g 0
#done
##### BET is not needed since ground truth images are already brain extracted and hsf_map_segs_groundtruth has aligned T1_orig images to brain extracted space
###### FLIRT ########
# Register T1 to MNI
for dir in "$pathT1"/$subj; do
flirt -in "$pathManual/${dir##*/}/${dir##*/}_T1_brain.nii.gz" -ref "$FSLDIR/data/standard/MNI152_T1_2mm_brain.nii.gz" -dof 12 -out "$pathT1/${dir##*/}/${dir##*/}_toMNIlin" -omat "$pathT1/${dir##*/}/${dir##*/}_toMNIlin.mat"
echo "Done: ${dir##*/}"
done
######## FNIRT ###########
# Transform T1 into MNI space using FNIRT
for dir in "$pathT1"/$subj; do
fnirt --in=$pathT1/${dir##*/}/T1_orig_ToBrain.nii.gz --aff="$pathT1/${dir##*/}/${dir##*/}_toMNIlin.mat" --config=$FSLDIR/etc/flirtsch/T1_2_MNI152_2mm.cnf --iout="$pathT1/${dir##*/}/${dir##*/}_toMNInonlin" --cout="$pathT1/${dir##*/}/${dir##*/}_toMNI_coef" --fout="$pathT1/${dir##*/}/${dir##*/}_toMNI_warp"
echo "Done: ${dir##*/}"
done
######### Warp_FN_FP_to_MNI #############
# Paths
# Variables
# Use warps from FNIRT to transform FN and FP maps into MNI space
for dir in "$pathT1"/$subj; do
for h in "${hemisphere[@]}"; do
for err in "${error[@]}"; do
applywarp -i "${pathAuto}/${dir##*/}/${dir##*/}_${h}_${err}.nii.gz" -r "$FSLDIR/data/standard/MNI152_T1_1mm" -w "$pathT1/${dir##*/}/${dir##*/}_toMNI_warp.nii.gz" -o "$pathT1/${dir##*/}/${subj}_${h}_${err}_MNI.nii.gz"
done
done
echo "Done: ${dir##*/}"
done