-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile_deepmedic_feature_maps.py
More file actions
46 lines (39 loc) · 1.71 KB
/
Copy pathcompile_deepmedic_feature_maps.py
File metadata and controls
46 lines (39 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import nibabel as nib
import nilearn
from nilearn import plotting
from main import load_files
import numpy as np
import matplotlib.pyplot as plt
def compile_deep_medic_feature_maps(path):
layers = ["layer" + str(x) for x in range(4)]
feature_map_files = load_files([path])
print(layers)
images_per_row = 10
for layer in layers:
feature_map_files = load_files([path + "\\" + layer])
feature_maps = [nib.load(x).get_data()[:, : 176, :] for x in feature_map_files]
n_features = len(feature_map_files)
print(n_features)
size = feature_maps[0].shape[-1]
n_cols = n_features // images_per_row
print(n_cols)
display_grid = np.zeros((size * n_cols, images_per_row * size))
for col in range(n_cols):
for row in range(images_per_row):
feature_map = feature_maps[col * images_per_row + row]
channel_image = feature_map[10, :, :]
channel_image -= channel_image.mean()
channel_image /= channel_image.std()
channel_image *= 64
channel_image += 128
display_grid[col * size : (col + 1) * size, row * size : (row + 1) * size] = channel_image
scale = 1. / size
plt.figure(figsize=(scale * display_grid.shape[1], scale * display_grid.shape[0]))
plt.title(layer)
plt.grid(False)
plt.imshow(display_grid, aspect='auto', cmap='viridis')
plt.savefig("D:\\Master\\Graphs\\featuremapsDeepMedic\\" + "pathway1" + layer + ".png")
plt.show()
# plotting.plot_roi(feature_maps[1], bg_img=None, cmap='Greys')
# plotting.show()
compile_deep_medic_feature_maps("D:\\Master\\features\\pathway1\\")