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