-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_resample_by_c3d.sh
74 lines (55 loc) · 1.76 KB
/
tool_resample_by_c3d.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
#!/usr/bin/env bash
# this script resample the image/segmentation nii files to a defined pixel dimension. (e.g., low res 1.5mm or high res 0.625mm)
# Get a list of patients.
patients=(/Data/McVeighLabSuper/wip/zhennong/nii-images/Abnormal/*/)
patients+=(/Data/McVeighLabSuper/wip/zhennong/nii-images/Normal/*/)
data_folder="/Data/McVeighLabSuper/wip/zhennong/nii-images"
save_folder="/Data/McVeighLabSuper/wip/zhennong/nii-images"
img_or_seg=1 # 1 is image, 0 is seg
if ((${img_or_seg} == 1))
then
img_folder="img-nii"
else
img_folder="seg-pred-0.625-4classes-connected-retouch"
fi
for p in ${patients[*]};
do
# Print the current patient.
# find out patientclass and patientid
patient_id=$(basename ${p})
patient_class=$(basename $(dirname ${p}))
p=${data_folder}${patient_class}/${patient_id}
echo ${p}
# assert whether originial files exist
if ! [ -d ${p}/${img_folder} ] || ! [ "$(ls -A ${p}/${img_folder})" ];then
echo "no image/seg"
continue
fi
# set output folder
if ((${img_or_seg} == 1))
then
o_dir=${save_folder}${patient_class}/${patient_id}/img-nii-1.5
else
o_dir=${save_folder}${patient_class}/${patient_id}/seg-nii-0.625-4classes-connected-retouch-downsample
fi
echo ${o_dir}
mkdir -p ${o_dir}
IMGS=(${p}/${img_folder}/*.nii.gz)
for i in $(seq 0 $(( ${#IMGS[*]} - 1 )));
do
i_file=${IMGS[${i}]}
echo ${i_file}
o_file=${o_dir}/$(basename ${i_file})
if [ -f ${o_file} ];then
echo "already done this file"
continue
else
if ((${img_or_seg} == 1))
then
c3d ${i_file} -interpolation Cubic -resample-mm 1.5x1.5x1.5mm -o ${o_file}
else
c3d ${i_file} -interpolation NearestNeighbor -resample-mm 1.5mmx1.5mmx1.5mm -o ${o_file}
fi
fi
done
done