-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVolumeViewer.py
64 lines (50 loc) · 1.9 KB
/
VolumeViewer.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
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
#import matplotlib.image as mpimg
import numpy as np
#####################################
# Volume Viewer in each dimension
# - Dakai Zhou
#######################################
def VolumeViewer(vol):
if not len(vol.shape) == 3:
raise ValueError("Please input 3D data.")
fig = plt.figure()
# 1st Dimension
ax1 = plt.subplot(131)
img1 = vol[0, :, :]
l1 = ax1.imshow(img1, cmap = plt.cm.gray, vmin = np.min(vol), vmax = np.max(vol))
axcolor = 'lightgoldenrodyellow'
# 2nd Dimension
ax2 = plt.subplot(132)
img2 = vol[:, 0, :]
l2 = ax2.imshow(img2, cmap = plt.cm.gray, vmin = np.min(vol), vmax = np.max(vol))
# 3nd Dimension
ax3 = plt.subplot(133)
img3 = vol[:, :, 0]
l3 = ax3.imshow(img3, cmap = plt.cm.gray, vmin = np.min(vol), vmax = np.max(vol))
axslice1 = plt.axes([0.25, 0.2, 0.65, 0.03], facecolor = axcolor)
axslice2 = plt.axes([0.25, 0.15, 0.65, 0.03], facecolor = axcolor)
axslice3 = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor = axcolor)
slider1 = Slider(axslice1, 'Slider1', 0, vol.shape[0]-1, valinit = 0, valstep = 1)
slider2 = Slider(axslice2, 'Slider2', 0, vol.shape[1]-1, valinit = 0, valstep = 1)
slider3 = Slider(axslice3, 'Slider3', 0, vol.shape[2]-1, valinit = 0, valstep = 1)
def update1(val):
idx1 = int(round(slider1.val))
img1 = vol[idx1, :, :]
l1.set_data(img1)
fig.canvas.draw()
def update2(val):
idx2 = int(round(slider2.val))
img2 = vol[:, idx2, :]
l2.set_data(img2)
fig.canvas.draw()
def update3(val):
idx3 = int(round(slider3.val))
img3 = vol[:, :, idx3]
l3.set_data(img3)
fig.canvas.draw()
slider1.on_changed(update1)
slider2.on_changed(update2)
slider3.on_changed(update3)
plt.show()