| Conditions | 2 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | from niprov.dependencies import Dependencies |
||
| 22 | def view(img, dependencies=Dependencies()): |
||
| 23 | libs = dependencies.getLibraries() |
||
| 24 | plt = libs.pyplot |
||
| 25 | nibabel = libs.nibabel |
||
| 26 | data = nibabel.load(img.path).get_data() |
||
| 27 | |||
| 28 | ## 3D |
||
| 29 | ndims = len(data.shape) |
||
| 30 | sliceOrder = [1, 0, 2] |
||
| 31 | |||
| 32 | fig, axs = plt.subplots(nrows=1, ncols=ndims) |
||
| 33 | |||
| 34 | for d in range(ndims): |
||
| 35 | slicing = [slice(None)]*ndims |
||
| 36 | slicing[sliceOrder[d]] = int(data.shape[d]/2) |
||
| 37 | axs[d].matshow(data[slicing].T, origin='lower', |
||
| 38 | cmap = plt.get_cmap('gray'), vmin = 0, vmax = data.max()) |
||
| 39 | axs[d].locator_params(nbins=3) |
||
| 40 | axs[d].tick_params(axis='both', which='major', labelsize=8) |
||
| 41 | |||
| 42 | plt.tight_layout() |
||
| 43 | |||
| 44 | fname = 'myplot.png' |
||
| 45 | plt.savefig(fname) |
||
| 46 | webbrowser.open(fname) |
||
| 47 |