forked from USC-LoBeS/style_transfer_harmonization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harmonize_images.sh
93 lines (66 loc) · 2.7 KB
/
harmonize_images.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
#!/bin/sh
if [ $# -lt 2 ]
then
echo "Usage: $0 <TARGET_DIR> <PREFIX> <CASE> <COPYTO_DIR>"
exit 1
fi
REF_IMG=$1
INP_PATH=$2
SAVEPATH=$3
MODELPATH=$4
ref_id=$(basename $REF_IMG .nii.gz)
echo
echo "-------------Reference image is-----------------"
echo "$REF_IMG"
echo "------------------------------------------------"
echo
python ./processing/convert_nii_to_slices_test.py --input_img $REF_IMG --save_path $SAVEPATH --is_ref True
REFPATH=${SAVEPATH}/ref/${ref_id}/
for INP_IMG in ${INP_PATH}/*.nii.gz;do
inp_id=$(basename $INP_IMG .nii.gz)
echo
echo "-------------source image now is-----------------"
echo "$INP_IMG"
echo "------------------------------------------------"
echo
python ./processing/convert_nii_to_slices_test.py --input_img $INP_IMG --save_path $SAVEPATH
SRCPATH=${SAVEPATH}/${inp_id}
TMPPATH=${SRCPATH}/npy
mkdir ${TMPPATH}
for subf in $SRCPATH/*; do
orient=$(basename $subf)
# Skip npy directory
if [ "$orient" = "npy" ]; then
continue
fi
echo
echo "--------------------------------------------------------------------------------"
echo "--------------------------------------------------------------------------------"
echo "Now the harmonization on................."
echo "$subf"
echo "--------------------------------------------------------------------------------"
echo "--------------------------------------------------------------------------------"
echo
echo $orient
python main.py --mode sample --resume_iter 200000 \
--checkpoint_dir ${MODELPATH}/checkpoints/ \
--result_dir ${TMPPATH} \
--src_dir ${subf} \
--ref_dir ${REFPATH}/$orient \
--val_batch_size 254
done
python ./processing/make_nii_from_3_orientations.py --input_img ${INP_IMG} --load_path ${TMPPATH} --save_path ${SRCPATH}
python ./processing/make_nii_from_3_orientations.py --input_img ${INP_IMG} --load_path ${TMPPATH} --save_path ${SRCPATH} --is_src True
# Add header to file
python ./processing/add_header.py --inpdir ${SRCPATH} --subject ${inp_id}
# Rescale Intensities
python ./processing/rescale_intensities.py --inpdir ${SAVEPATH} --refdir ${REF_IMG} --subject ${inp_id} --outdir ${SAVEPATH}
# Maskbrain, removing artifacts
fslmaths ${SRCPATH}/${inp_id}_harm_whead_rescaled.nii.gz \
-mas ${INP_PATH}/${inp_id}.nii.gz \
${SRCPATH}/${inp_id}_harm_whead_rescaled_masked.nii.gz
echo "Done Masking Output"
echo
echo "Final Output saved at:"
echo "${SRCPATH}/${inp_id}_harm_whead_rescaled_masked.nii.gz"
done