|
a |
|
b/data.py |
|
|
1 |
import os |
|
|
2 |
import pydicom |
|
|
3 |
import matplotlib.pylab as plt |
|
|
4 |
import numpy as np |
|
|
5 |
|
|
|
6 |
path = '/media/tiger/zzr/rsna' |
|
|
7 |
trainPath = os.path.join(path, 'test') |
|
|
8 |
|
|
|
9 |
def preprocess(img): |
|
|
10 |
ds = pydicom.dcmread(img) |
|
|
11 |
try: |
|
|
12 |
windowCenter = int(ds.WindowCenter[0]) |
|
|
13 |
windowWidth = int(ds.WindowWidth[0]) |
|
|
14 |
except: |
|
|
15 |
windowCenter = int(ds.WindowCenter) |
|
|
16 |
windowWidth = int(ds.WindowWidth) |
|
|
17 |
intercept = ds.RescaleIntercept |
|
|
18 |
slope = ds.RescaleSlope |
|
|
19 |
data = ds.pixel_array |
|
|
20 |
data = np.clip(data * slope + intercept, windowCenter - windowWidth/2, windowCenter + windowWidth/2) |
|
|
21 |
plt.imshow(data, cmap='gray') |
|
|
22 |
plt.show() |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
if __name__ == '__main__': |
|
|
26 |
dataList = sorted(os.listdir(trainPath)) |
|
|
27 |
for i in dataList: |
|
|
28 |
print(i) |
|
|
29 |
img = os.path.join(trainPath, i) |
|
|
30 |
preprocess(img) |