python scroll thorugh 3d volumes

Solutions on MaxInterview for python scroll thorugh 3d volumes by the best coders in the world

showing results for - "python scroll thorugh 3d volumes"
Chiara
13 Aug 2019
1def multi_slice_viewer(volume):
2    remove_keymap_conflicts({'j', 'k'})
3    fig, ax = plt.subplots()
4    ax.volume = volume
5    ax.index = volume.shape[0] // 2
6    ax.imshow(volume[ax.index])
7    fig.canvas.mpl_connect('key_press_event', process_key)
8
9def process_key(event):
10    fig = event.canvas.figure
11    ax = fig.axes[0]
12    if event.key == 'j':
13        previous_slice(ax)
14    elif event.key == 'k':
15        next_slice(ax)
16    fig.canvas.draw()
17
18def previous_slice(ax):
19    volume = ax.volume
20    ax.index = (ax.index - 1) % volume.shape[0]  # wrap around using %
21    ax.images[0].set_array(volume[ax.index])
22
23def next_slice(ax):
24    volume = ax.volume
25    ax.index = (ax.index + 1) % volume.shape[0]
26    ax.images[0].set_array(volume[ax.index])