Created
          September 21, 2017 07:46 
        
      - 
      
- 
        Save bodokaiser/2a9c5c474fd3a222ec3a6ddabc3c7cc3 to your computer and use it in GitHub Desktop. 
    project 3d volumes along each axes.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import math | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| from matplotlib.widgets import Slider | |
| def show_volumes_projection(volumes): | |
| n = len(volumes) | |
| fig, axes = plt.subplots(n, 3) | |
| plt.subplots_adjust(left=0.25, bottom=0.25) | |
| vmin = 0 | |
| vmax = 1 | |
| images = [( | |
| axes[i][0].imshow(np.rot90(v[:, :, 0]), vmin=vmin, vmax=vmax), | |
| axes[i][1].imshow(np.rot90(v[:, 0, :]), vmin=vmin, vmax=vmax), | |
| axes[i][2].imshow(np.rot90(v[0, :, :]), vmin=vmin, vmax=vmax), | |
| ) for i, v in enumerate(volumes)] | |
| ax1 = plt.axes([0.15, 0.10, 0.65, 0.03]) | |
| ax2 = plt.axes([0.15, 0.15, 0.65, 0.03]) | |
| ax3 = plt.axes([0.15, 0.20, 0.65, 0.03]) | |
| shape = volumes[0].shape | |
| sl1 = Slider(ax1, 'Coronal', 0, shape[2] - 1, valfmt='%d') | |
| sl2 = Slider(ax2, 'Sagital', 0, shape[1] - 1, valfmt='%d') | |
| sl3 = Slider(ax3, 'Transversal', 0, shape[0] - 1, valfmt='%d') | |
| def update_im1(value): | |
| for i, image in enumerate(images): | |
| image[0].set_data(np.rot90(volumes[i][:, :, math.ceil(value)])) | |
| fig.canvas.draw_idle() | |
| def update_im2(value): | |
| for i, image in enumerate(images): | |
| image[1].set_data(np.rot90(volumes[i][:, math.ceil(value), :])) | |
| fig.canvas.draw_idle() | |
| def update_im3(value): | |
| for i, image in enumerate(images): | |
| image[2].set_data(np.rot90(volumes[i][math.ceil(value), :, :])) | |
| fig.canvas.draw_idle() | |
| sl1.on_changed(update_im1) | |
| sl2.on_changed(update_im2) | |
| sl3.on_changed(update_im3) | |
| plt.show() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment