Completed
Pull Request — master (#136)
by Jasper
01:19
created

view()   B

Complexity

Conditions 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
1
from niprov.dependencies import Dependencies
2
import webbrowser
3
4
def view(img, dependencies=Dependencies()):
5
    libs = dependencies.getLibraries()
6
    plt = libs.pyplot
7
    nibabel = libs.nibabel
8
    data = nibabel.load(img.path).get_data()
9
10
    ## 3D
11
    ndims = len(data.shape)
12
    sliceOrder = [1, 0, 2]
13
14
    fig, axs = plt.subplots(nrows=1, ncols=ndims)
15
16
    for d in range(ndims):
17
        slicing = [slice(None)]*ndims
18
        slicing[sliceOrder[d]] = int(data.shape[d]/2)
19
        axs[d].matshow(data[slicing].T, origin='lower', 
20
            cmap = plt.get_cmap('gray'), vmin = 0, vmax = data.max())
21
        axs[d].locator_params(nbins=3)
22
        axs[d].tick_params(axis='both', which='major', labelsize=8)
23
24
    plt.tight_layout()
25
26
    fname = 'myplot.png'
27
    plt.savefig(fname)
28
    webbrowser.open(fname)
29