-
Notifications
You must be signed in to change notification settings - Fork 2
/
EDA_createPNGs.py
executable file
·80 lines (50 loc) · 1.46 KB
/
EDA_createPNGs.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
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
# coding: utf-8
# In[1]:
import pydicom
import os
import matplotlib.pyplot as plt
import numpy as np
import csv
import cv2
import PIL
import tqdm
# In[2]:
labelDict = {}
with open('locationData.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
next(csv_reader)
for row in csv_reader:
identifier = str(row[0]).zfill(4)
tubePresentBool = row[1]=='Y'
if tubePresentBool:
xCoord = float(row[2])
yCoord = float(row[3])
else:
xCoord = 0.0
yCoord = 0.0
labelDict[identifier] = [tubePresentBool, xCoord, yCoord]
# In[ ]:
IDlist = list(labelDict.keys())
# In[ ]:
missingIDs = []
for eachID in tqdm.tqdm(IDlist):
try:
ds = pydicom.read_file('DICOMS/'+eachID + '.dcm')
pix = ds.pixel_array
img = PIL.Image.fromarray(np.uint8((pix/pix.max())*255))
img.save('PNG_all/'+ eachID + '.png')
except:
missingIDs.append(eachID)
# In[ ]:
print(missingIDs)
# In[ ]:
for eachID in tqdm.tqdm(IDlist):
if labelDict[eachID][0]:
try:
ds = pydicom.read_file('DICOMS/'+eachID + '.dcm')
pix = ds.pixel_array
origX = labelDict[eachID][1]
origY = labelDict[eachID][2]
cv2.circle(pix,(int(origX), int(origY)), 100, (0,255,0), 5)
img = PIL.Image.fromarray(np.uint8((pix/pix.max())*255))
img.save('PNG_tubesAnnotated/'+ eachID + '.png')