-
Notifications
You must be signed in to change notification settings - Fork 2
/
exampleLungLobeEstimation.sh
96 lines (72 loc) · 2.92 KB
/
exampleLungLobeEstimation.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
92
93
94
95
96
dataDir=./
outputDir="${dataDir}/Output/"
mkdir -p ${outputDir}
intensityImages=( `ls ${dataDir}/ProtonImages/*H1.nii.gz` );
lungMaskImages=( `ls ${dataDir}/ProtonLungMasks/*Mask.nii.gz` );
lobeMaskImages=( `ls ${dataDir}/ProtonLobeMasks/*Lobes.nii.gz` );
############
#
# For both the lung and lobe estimation, we need to normalize to the target
# image. Simply as a matter of convenience, we're going to make the target
# image the first image in the arrays extracted above, i.e. ${intensityImages[0]}
#
targetImage=${intensityImages[0]}
targetLungMask=${lungMaskImages[0]}
targetLobeMask=${lobeMaskImages[0]}
targetLungMaskEstimated="${outputDir}/targetLungMaskEstimated.nii.gz"
targetLobeMaskEstimated="${outputDir}/targetLobeMaskEstimated.nii.gz"
warpedImages=()
warpedLungMasks=()
warpedLobeMasks=()
for (( i = 1; i < ${#intensityImages[@]}; i++ ))
do
outputPrefix=${outputDir}/proton${i}_
normalizeCommand="antsRegistrationSyNQuick.sh -d 3 -f $targetImage -m ${intensityImages[$i]} -o $outputPrefix -t b -s 26"
$normalizeCommand
# We transform the lung and lobe labels to the space of the target image
transformCommand="antsApplyTransforms -d 3 -v 1 -i ${lungMaskImages[$i]} -r ${intensityImages[0]} -o ${outputPrefix}LungsWarped.nii.gz -n NearestNeighbor -t ${outputPrefix}1Warp.nii.gz -t ${outputPrefix}0GenericAffine.mat"
$transformCommand
transformCommand="antsApplyTransforms -d 3 -v 1 -i ${lobeMaskImages[$i]} -r ${intensityImages[0]} -o ${outputPrefix}LobesWarped.nii.gz -n NearestNeighbor -t ${outputPrefix}1Warp.nii.gz -t ${outputPrefix}0GenericAffine.mat"
$transformCommand
warpedImages[${#warpedImages[@]}]="${outputPrefix}Warped.nii.gz"
warpedLungMasks[${#warpedLungMasks[@]}]="${outputPrefix}LungsWarped.nii.gz"
warpedLobeMasks[${#warpedLobeMasks[@]}]="${outputPrefix}LobesWarped.nii.gz"
done
##############
#
# Estimate target lung mask
#
jointFusionCommand="antsJointFusion -d 3 -v 1 -t $targetImage -o $targetLungMaskEstimated -p 2 -s 3 -a 0.1"
for (( i = 0; i < ${#warpedImages[@]}; i++ ))
do
jointFusionCommand="${jointFusionCommand} -g ${warpedImages[$i]}"
jointFusionCommand="${jointFusionCommand} -l ${warpedLungMasks[$i]}"
done
$jointFusionCommand
##############
#
# Estimate target lobe mask
#
jointFusionCommand="antsJointFusion -d 3 -v 1 -t $targetImage -o $targetLobeMaskEstimated -p 2 -s 3 -a 0.1"
for (( i = 0; i < ${#warpedImages[@]}; i++ ))
do
jointFusionCommand="${jointFusionCommand} -g ${warpedImages[$i]}"
jointFusionCommand="${jointFusionCommand} -l ${warpedLobeMasks[$i]}"
done
$jointFusionCommand
##############
#
# Perform label overlap evaluation
#
echo
echo
echo
echo
echo "Evaluation"
echo
echo "Lung mask estimation label overlap measures:"
LabelOverlapMeasures 3 $targetLungMask $targetLungMaskEstimated
echo
echo
echo "Lobe mask estimation label overlap measures:"
LabelOverlapMeasures 3 $targetLobeMask $targetLobeMaskEstimated