Passed
Push — master ( 4b2fda...da3585 )
by Fernando
01:40
created

torchio.datasets.fpg.FPG.plot()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 3
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import urllib.parse
2
from torchvision.datasets.utils import download_url
3
from .. import Subject, ScalarImage, LabelMap, DATA_REPO
4
from ..utils import get_torchio_cache_dir
5
from ..data.io import read_matrix
6
7
8
class FPG(Subject):
9
    """Some images of myself for testing."""
10
    def __init__(self):
11
        repo_dir = urllib.parse.urljoin(DATA_REPO, 'fernando/')
12
13
        self.filenames = {
14
            't1': 't1.nii.gz',
15
            'seg': 't1_seg_gif.nii.gz',
16
            'rigid': 't1_to_mni.tfm',
17
            'affine': 't1_to_mni_affine.h5',
18
        }
19
20
        download_root = get_torchio_cache_dir() / 'fpg'
21
        for filename in self.filenames.values():
22
            download_url(
23
                urllib.parse.urljoin(repo_dir, filename),
24
                download_root,
25
                filename=filename,
26
            )
27
28
        rigid = read_matrix(download_root / self.filenames['rigid'])
29
        affine = read_matrix(download_root / self.filenames['affine'])
30
        subject_dict = {
31
            't1': ScalarImage(
32
                download_root / self.filenames['t1'],
33
                rigid_matrix=rigid,
34
                affine_matrix=affine,
35
            ),
36
            'seg': LabelMap(
37
                download_root / self.filenames['seg'],
38
                rigid_matrix=rigid,
39
                affine_matrix=affine,
40
            ),
41
        }
42
        super().__init__(subject_dict)
43
        self.gif_colors = GIF_COLORS
44
45
    def plot(self, *args, **kwargs):
46
        super().plot(*args, **kwargs, cmap_dict=dict(seg=self.gif_colors))
47
48
49
GIF_COLORS = {
50
    0: (0, 0, 0),
51
    1: (0, 0, 0),
52
    5: (127, 255, 212),
53
    12: (240, 230, 140),
54
    16: (176, 48, 96),
55
    24: (48, 176, 96),
56
    31: (48, 176, 96),
57
    32: (103, 255, 255),
58
    33: (103, 255, 255),
59
    35: (238, 186, 243),
60
    36: (119, 159, 176),
61
    37: (122, 186, 220),
62
    38: (122, 186, 220),
63
    39: (96, 204, 96),
64
    40: (96, 204, 96),
65
    41: (220, 247, 164),
66
    42: (220, 247, 164),
67
    43: (205, 62, 78),
68
    44: (205, 62, 78),
69
    45: (225, 225, 225),
70
    46: (225, 225, 225),
71
    47: (60, 60, 60),
72
    48: (220, 216, 20),
73
    49: (220, 216, 20),
74
    50: (196, 58, 250),
75
    51: (196, 58, 250),
76
    52: (120, 18, 134),
77
    53: (120, 18, 134),
78
    54: (255, 165, 0),
79
    55: (255, 165, 0),
80
    56: (12, 48, 255),
81
    57: (12, 48, 225),
82
    58: (236, 13, 176),
83
    59: (236, 13, 176),
84
    60: (0, 118, 14),
85
    61: (0, 118, 14),
86
    62: (165, 42, 42),
87
    63: (165, 42, 42),
88
    64: (160, 32, 240),
89
    65: (160, 32, 240),
90
    66: (56, 192, 255),
91
    67: (56, 192, 255),
92
    70: (255, 225, 225),
93
    72: (184, 237, 194),
94
    73: (180, 231, 250),
95
    74: (225, 183, 231),
96
    76: (180, 180, 180),
97
    77: (180, 180, 180),
98
    81: (245, 255, 200),
99
    82: (255, 230, 255),
100
    83: (245, 245, 245),
101
    84: (220, 255, 220),
102
    85: (220, 220, 220),
103
    86: (200, 255, 255),
104
    87: (250, 220, 200),
105
    89: (245, 255, 200),
106
    90: (255, 230, 255),
107
    91: (245, 245, 245),
108
    92: (220, 255, 220),
109
    93: (220, 220, 220),
110
    94: (200, 255, 255),
111
    96: (140, 125, 255),
112
    97: (140, 125, 255),
113
    101: (255, 62, 150),
114
    102: (255, 62, 150),
115
    103: (160, 82, 45),
116
    104: (160, 82, 45),
117
    105: (165, 42, 42),
118
    106: (165, 42, 42),
119
    107: (205, 91, 69),
120
    108: (205, 91, 69),
121
    109: (100, 149, 237),
122
    110: (100, 149, 237),
123
    113: (135, 206, 235),
124
    114: (135, 206, 235),
125
    115: (250, 128, 114),
126
    116: (250, 128, 114),
127
    117: (255, 255, 0),
128
    118: (255, 255, 0),
129
    119: (221, 160, 221),
130
    120: (221, 160, 221),
131
    121: (0, 238, 0),
132
    122: (0, 238, 0),
133
    123: (205, 92, 92),
134
    124: (205, 92, 92),
135
    125: (176, 48, 96),
136
    126: (176, 48, 96),
137
    129: (152, 251, 152),
138
    130: (152, 251, 152),
139
    133: (50, 205, 50),
140
    134: (50, 205, 50),
141
    135: (0, 100, 0),
142
    136: (0, 100, 0),
143
    137: (173, 216, 230),
144
    138: (173, 216, 230),
145
    139: (153, 50, 204),
146
    140: (153, 50, 204),
147
    141: (160, 32, 240),
148
    142: (160, 32, 240),
149
    143: (0, 206, 208),
150
    144: (0, 206, 208),
151
    145: (51, 50, 135),
152
    146: (51, 50, 135),
153
    147: (135, 50, 74),
154
    148: (135, 50, 74),
155
    149: (218, 112, 214),
156
    150: (218, 112, 214),
157
    151: (240, 230, 140),
158
    152: (240, 230, 140),
159
    153: (255, 255, 0),
160
    154: (255, 255, 0),
161
    155: (255, 110, 180),
162
    156: (255, 110, 180),
163
    157: (0, 255, 255),
164
    158: (0, 255, 255),
165
    161: (100, 50, 100),
166
    162: (100, 50, 100),
167
    163: (178, 34, 34),
168
    164: (178, 34, 34),
169
    165: (255, 0, 255),
170
    166: (255, 0, 255),
171
    167: (39, 64, 139),
172
    168: (39, 64, 139),
173
    169: (255, 99, 71),
174
    170: (255, 99, 71),
175
    171: (255, 69, 0),
176
    172: (255, 69, 0),
177
    173: (210, 180, 140),
178
    174: (210, 180, 140),
179
    175: (0, 255, 127),
180
    176: (0, 255, 127),
181
    177: (74, 155, 60),
182
    178: (74, 155, 60),
183
    179: (255, 215, 0),
184
    180: (255, 215, 0),
185
    181: (238, 0, 0),
186
    182: (238, 0, 0),
187
    183: (46, 139, 87),
188
    184: (46, 139, 87),
189
    185: (238, 201, 0),
190
    186: (238, 201, 0),
191
    187: (102, 205, 170),
192
    188: (102, 205, 170),
193
    191: (255, 218, 185),
194
    192: (255, 218, 185),
195
    193: (238, 130, 238),
196
    194: (238, 130, 238),
197
    195: (255, 165, 0),
198
    196: (255, 165, 0),
199
    197: (255, 192, 203),
200
    198: (255, 192, 203),
201
    199: (244, 222, 179),
202
    200: (244, 222, 179),
203
    201: (208, 32, 144),
204
    202: (208, 32, 144),
205
    203: (34, 139, 34),
206
    204: (34, 139, 34),
207
    205: (125, 255, 212),
208
    206: (127, 255, 212),
209
    207: (0, 0, 128),
210
    208: (0, 0, 128),
211
}
212