-
Notifications
You must be signed in to change notification settings - Fork 0
/
ID-Dicoms.sh
executable file
·99 lines (97 loc) · 2.23 KB
/
ID-Dicoms.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
rm log.log
for i in */
do
cd $i
if [ -a doney.log ]; then
cd ..
echo $i
echo "already named moving on"
continue
fi
mkdir -p dicom
mv *.dcm dicom
cd dicom
#var=$(find *.dcm -print -quit)
for var in *.dcm
do
gdcmraw -i $var -t 20,1002 -o slicenumber.log
slices=$(cat slicenumber.log)
if [ $slices -gt "100" ]; then
echo $i
echo $var
echo "###############################" >> ../../log.log
echo $var >> ../../log.log
gdcmdump $var | grep "Patient ID" >> ../../log.log
gdcmraw -i $var -t 10,20 -o ../../ID.log
ID=$(cat ../../ID.log)
gdcmdump $var | grep "Modality" >> ../../log.log
gdcmdump $var | grep "Acquisition Date" >> ../../log.log
gdcmraw -i $var -t 8,22 -o ../../Date.log
Date=$(cat ../../Date.log)
gdcmdump $var | grep "Images in Acquisition" >> ../../log.log
gdcmdump $var | grep "Last image number used" >> ../../log.log
#cd ..
outputname=${ID% TWH }
outputname+="-"
outputname+=$Date
#mv $i $outputname
break
fi
done
cd ..
cd ..
if [ -n "$outputname" ]; then
mv $i $outputname
fi
rm Date.log
rm ID.log
done
for dirs in *-*/
do
cd $dirs
echo $dirs
if [ -a doney.log ]; then
cd ..
#echo $dirs
echo "already done moving on."
continue
fi
cd dicom
for file in *.dcm; do gdcmraw -i $file -t 8,103e -o name.log; echo $(cat name.log) >> names.txt; done
cat names.txt | sort | uniq >> new.txt
while read filetype
do
mkdir -p ../"$filetype"
done < new.txt
for file in *.dcm
do
gdcmraw -i $file -t 8,103e -o name.log
name=$(cat name.log)
while read filetype
do
if [[ $name = "$filetype " ]]; then
ln -s -t ../"$filetype" ../dicom/$file
elif [[ $name = "$filetype" ]]; then
ln -s -t ../"$filetype" ../dicom/$file
fi
done < new.txt
done
names.txt name.log slicenumber.log
cd ..
while read filetype
do
cd "$filetype"
for i in *.dcm
do
gdcmconv $i $i -w
done
cd ..
dcm2nii -d N -e N -f Y -i N -p N $filetype
rm "$filetype"/*o*.nii.gz
#rmdir "$filetype"
done < dicom/new.txt
rm dicom/new.txt
echo $dirs >> doney.log
cd ..
echo "##############"
done