-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrool
56 lines (43 loc) · 1.46 KB
/
scrool
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
import numpy as np
import matplotlib.pyplot as plt
import os, glob
import pydicom
import pylab as pl
import sys
import matplotlib.path as mplPath
%matplotlib widget
class IndexTracker(object):
def __init__(self, ax, X):
self.ax = ax
ax.set_title('Scroll to Navigate through the DICOM Image Slices')
self.X = X
rows, cols, self.slices = X.shape
self.ind = self.slices//2
self.im = ax.imshow(self.X[:, :, self.ind])
self.update()
def onscroll(self, event):
print("%s %s" % (event.button, event.step))
if event.button == 'up':
self.ind = (self.ind + 1) % self.slices
else:
self.ind = (self.ind - 1) % self.slices
self.update()
def update(self):
self.im.set_data(self.X[:, :, self.ind])
ax.set_ylabel('Slice Number: %s' % self.ind)
self.im.axes.figure.canvas.draw()
fig, ax = plt.subplots(1,1)
# E:\PycharmProjects\pythonProject\exame\CQ500CT257\Unknown Study\CT 0.625mm
os.system("tree E:/PycharmProjects/pythonProject/exame/CQ500CT257/Unknown Study")
plots = []
for f in glob.glob("E://PycharmProjects//pythonProject//exame//CQ500CT257//Unknown Study//CT 0.625mm//*.dcm"):
pass
# filename = f.split("/")[-1]
ds = pydicom.dcmread(f)
pix = ds.pixel_array
pix = pix*1+(-1024)
plots.append(pix)
y = np.dstack(plots)
tracker = IndexTracker(ax, y)
fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
plt.show()