-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_inputs.sh
executable file
·150 lines (106 loc) · 4.13 KB
/
preprocess_inputs.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#/bin/bash
#$ -S /bin/bash
set -x -e
ROOT="/Users/sravikumar/Box Sync/PennPhD/Research/PICSL/exvivo_mtl_unet"
#ROOT='/home/sadhana-ravikumar/Documents/Sadhana/exvivo_cortex_unet'
ATLAS_DIR="/Users/sravikumar/Box Sync/PennPhD/Research/PICSL/atlasPHG2019/inputs"
INPUTS="$ROOT/inputs"
DATADIR="$ROOT/data_csv"
CODEDIR="$ROOT/code"
SUBJ_TXT=$ROOT/subj_train_fold1.txt
#IND_ALL="$(cat "$SUBJ_TXT")"
function main()
{
mkdir -p $DATADIR
process_inputs all
#process_inputs train
#process_inputs test
Preparation
# PreparationTest
# PreparePulkitData
}
function process_inputs()
{
mode=${1?}
FILE=$ROOT/subj_${mode}.txt
N=$(cat "$FILE" | wc -l | sed 's/^ *//g')
for ((i=1;i<=$N;i++)); do
LINE=$(cat "$FILE" | head -n $i | tail -n 1)
id=$(echo $LINE | cut -d ' ' -f 1)
echo $id
WDIR=$ROOT/preproc_${mode}_${N}
mkdir -p "$WDIR"
mkdir -p "$WDIR/mri" "$WDIR/dmap" "$WDIR/seg" "$WDIR/intermediate" "$WDIR/seg_nosrlm"
mkdir -p "$WDIR/mri_raw" "$WDIR/seg_raw" "$WDIR/seg_atlas"
#echo "Normalizing image for $id"
IMG=$INPUTS/${id}/${id}_clip_n4.nii.gz
SEG=$INPUTS/${id}/${id}_multilabel_corrected_seg_whippo.nii.gz
DMAP=$INPUTS/${id}/${id}_coords-IO.nii.gz
SRLM_SEG=$INPUTS/${id}/${id}_axisalign_srlm_sr.nii.gz
ATLAS_SEG=$ATLAS_DIR/${id}/${id}_axisalign_phg_cs_v2.nii.gz
if [[ ! -f $ATLAS_SEG ]];then
ATLAS_SEG=$ATLAS_DIR/${id}/${id}_axisalign_phg_cs.nii.gz
fi
IMG_TRIM=$WDIR/mri/${id}_trimmed_img.nii.gz
SEG_TRIM=$WDIR/seg/${id}_trimmed_phg.nii.gz
SEG_NOSRLM_TRIM=$WDIR/seg_nosrlm/${id}_trimmed_phg_nosrlm.nii.gz
DMAP_TRIM=$WDIR/dmap/${id}_trimmed_dmap.nii.gz
SEG_COMB=$WDIR/intermediate/${id}_multilabel_wsrlm.nii.gz
SEG_ATLAS=$WDIR/seg_atlas/${id}_phg.nii.gz
#Combine srlm with multilabel seg
#c3d "$SEG" -replace 4 5 1 7 -as MS "$SRLM_SEG" -add -replace 6 4 8 4 7 1 -o "$SEG_COMB"
ln -sf "$IMG" "$WDIR/mri_raw/${id}_img.nii.gz"
ln -sf "$SEG_COMB" "$WDIR/seg_raw/${id}_phg.nii.gz"
c3d "$ATLAS_SEG" -replace 2 1 4 5 3 5 -retain-labels 5 -as LAT \
"$SEG_COMB" -replace 4 1 5 1 -thresh 1 1 1 0 -push LAT -times "$SEG_COMB" -add -o "$SEG_ATLAS"
<<"DONE"
#Trim input image to only contain segmented region
c3d "$SEG_COMB" -trim 0vox -o "$SEG_TRIM" -thresh -inf inf 1 0 -popas MASK "$IMG" \
-push MASK -reslice-identity -as R "$IMG" -add -push R -times -trim 0vox \
-shift -1 -o "$IMG_TRIM" \
"$DMAP" -push R -add -push R -times -trim 0vox -shift -1 -o "$DMAP_TRIM"
c3d "$SEG" -trim 0vox -o "$SEG_NOSRLM_TRIM"
#Downsample the trimmed input image since such a high res is not required. Patch will capture more info
# c3d $IMG_TRIM -resample 75% -o $INPUTS/${id}/${id}_downsample_img.nii.gz
# c3d $SEG_TRIM -resample 75% -o $INPUTS/${id}/${id}_downsample_phg.nii.gz
# Post processing to visualize test results
DONE
done
}
function Preparation()
{
N=$(cat $SUBJ_TXT | wc -l)
rm -rf $DATADIR/split_nosrlm.csv
for ((i=1;i<=${N};i++)); do
LINE=$(cat $SUBJ_TXT | head -n $i | tail -n 1)
id=$(echo $LINE | cut -d ' ' -f 1)
read dummmy type idint <<< $(cat $SUBJ_TXT | grep $id)
IMG=$INPUTS/mri/${id}_trimmed_img.nii.gz
SEG=$INPUTS/seg/${id}_trimmed_phg_nosrlm.nii.gz
DMAP=$INPUTS/dmap/${id}_trimmed_dmap.nii.gz
echo "$IMG,$SEG,$idint,"Control",$type,$DMAP" >> $DATADIR/split_nosrlm.csv
done
}
# Jan 6 - got rid of test dataset. Can cross validate instead to make use of all data
function PreparationTest()
{
N=$(cat $ROOT/subj_test.txt | wc -l)
rm -rf $DATADIR/split_test.csv
for ((i=1;i<=${N};i++)); do
LINE=$(cat $ROOT/subj_test.txt | head -n $i | tail -n 1)
id=$(echo $LINE | cut -d ' ' -f 1)
read dummmy type idint <<< $(cat $ROOT/subj_test.txt | grep $id)
IMG=$INPUTS/${id}/${id}_trimmed_img.nii.gz
SEG=$INPUTS/${id}/${id}_trimmed_phg.nii.gz
echo "$IMG,$SEG,$idint,"Control",$type" >> $DATADIR/split_test.csv
done
}
function PreparePulkitData()
{
for filename in /home/sadhana-ravikumar/Documents/Sadhana/mtl94_forpulkit/*.nii.gz; do
file=$(basename $filename)
id=$(echo $file | cut -d_ -f1)
echo "$filename,$filename,$id,"Control","test"" >> $DATADIR/test_pulkit.csv
done
}
main