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

Polaroid.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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