-
Notifications
You must be signed in to change notification settings - Fork 5
/
train.py
51 lines (43 loc) · 1.62 KB
/
train.py
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
'''
Created on May 17, 2016
This takes from
https://pyscience.wordpress.com/2014/09/08/dicom-in-python-importing-medical-image-data-into-numpy-with-pydicom-and-vtk/
@author: bhoff
'''
import dicom
import os
import sys
from gzip import GzipFile
import time
def writeProgress(pct):
f = open('/progress.txt', 'w')
f.write(str(pct)+'\n')
f.close()
if __name__ == '__main__':
#PathDicom = "/trainingData"
PathDicom = sys.argv[1]
i=0
n=len(os.listdir(PathDicom))
for filename in os.listdir(PathDicom):
if ".dcm" in filename.lower():
sys.stdout.write("{}: ".format(filename))
try:
if ".dcm.gz" in filename.lower():
RefDs = dicom.read_file(GzipFile(os.path.join(PathDicom,filename)))
else:
RefDs = dicom.read_file(os.path.join(PathDicom,filename))
# RefDs.dir has lots of info
#print(RefDs.dir)
firsttime=True
sys.stdout.write('file size (MB): {}, '.format(os.path.getsize(PathDicom+"/"+filename)/1024000))
for label in ['PatientID', 'StudyDate', 'PatientAge', 'SeriesDescription', 'Rows', 'Columns']:
if (firsttime):
firsttime=False
else:
sys.stdout.write(', ')
sys.stdout.write("{}: {}".format(label, RefDs.data_element(label).value))
print("")
except:
print(" ** failed to process file **")
i=i+1
writeProgress(float(i)*float(100)/float(n))