-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo_eigenmode_visualization.m
143 lines (111 loc) · 6.24 KB
/
demo_eigenmode_visualization.m
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% demo_eigenmode_visualization.m
%%%
%%% MATLAB script to demonstrate how to visualize surface and volume
%%% eigenmodes
%%%
%%% NOTE 1: The script can also be used to visualize other types of surface
%%% eigenmodes (e.g., connectome eigenmodes). Just change the
%%% eigenmodes variable below. However, make sure that the
%%% variable is an array of size
%%% [number of vertices x number of modes].
%%% NOTE 2: The script can also be used to visualize other types of volume
%%% eigenmodes (e.g., functional gradients). Just change the
%%% V_eigenmodes variable below. However, make sure that the
%%% variable is a 4D array of size
%%% [number of voxels x number of voxels x number of voxels x number of modes].
%%%
%%% Original: James Pang, Monash University, 2022
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Load relevant repository MATLAB functions
addpath(genpath('functions_matlab'));
%% Visualize surface eigenmodes
surface_interest = 'fsLR_32k';
hemisphere = 'lh';
mesh_interest = 'midthickness';
% =========================================================================
% Load surface and eigenmodes
% =========================================================================
% Load surface file
[vertices, faces] = read_vtk(sprintf('data/template_surfaces_volumes/%s_%s-%s.vtk', surface_interest, mesh_interest, hemisphere));
surface_midthickness.vertices = vertices';
surface_midthickness.faces = faces';
% Load cortex mask
cortex = dlmread(sprintf('data/template_surfaces_volumes/%s_cortex-%s_mask.txt', surface_interest, hemisphere));
cortex_ind = find(cortex);
% Load 50 fsLR_32k template midthickness surface eigenmodes
num_modes = 50;
eigenmodes = dlmread(sprintf('data/examples/fsLR_32k_midthickness-%s_emode_%i.txt', hemisphere, num_modes));
% Replace above line with the one below and make num_modes = 200 if using the 200 modes provided at data/template_eigenmodes
% eigenmodes = dlmread(sprintf('data/template_eigenmodes/fsLR_32k_midthickness-%s_emode_%i.txt', hemisphere, num_modes));
% =========================================================================
% Visualize one eigenmode
% =========================================================================
% In this example, the 2nd eigenmode
mode_interest = 2;
surface_to_plot = surface_midthickness;
data_to_plot = eigenmodes(:, mode_interest);
medial_wall = find(cortex==0);
% with medial wall view
with_medial = 1;
fig = draw_surface_bluewhitered_dull(surface_to_plot, data_to_plot, hemisphere, medial_wall, with_medial);
fig.Name = sprintf('Single surface eigenmode with medial wall view (mode = %i)', mode_interest);
% without medial wall view
with_medial = 0;
fig = draw_surface_bluewhitered_dull(surface_to_plot, data_to_plot, hemisphere, medial_wall, with_medial);
fig.Name = sprintf('Single surface eigenmode without medial wall view (mode = %i)', mode_interest);
% =========================================================================
% Visualize multiple eigenmodes
% =========================================================================
% In this example, the 1st to 5th eigenmodes
mode_interest = [1:5];
surface_to_plot = surface_midthickness;
data_to_plot = eigenmodes(:, mode_interest);
medial_wall = find(cortex==0);
% with medial wall view
with_medial = 1;
fig = draw_surface_bluewhitered_gallery_dull(surface_to_plot, data_to_plot, hemisphere, medial_wall, with_medial);
fig.Name = 'Multiple surface eigenmodes with medial wall view';
% without medial wall view
with_medial = 0;
fig = draw_surface_bluewhitered_gallery_dull(surface_to_plot, data_to_plot, hemisphere, medial_wall, with_medial);
fig.Name = 'Multiple surface eigenmodes without medial wall view';
%% Visualize volume eigenmodes (in this example, eigenmodes of the thalamus)
% NOTE: Subcortical volume masks and eigenmodes for striatum (striatum) and
% hippocampus (hippo) are also provided in the data folder for you to
% use. Just change the structure variable below.
hemisphere = 'lh';
structure = 'tha';
% =========================================================================
% Load volume mask and eigenmodes
% =========================================================================
% Load mask file
mask_filename = sprintf('data/template_surfaces_volumes/hcp_%s-%s_thr25.nii.gz', structure, hemisphere);
V_mask = niftiread(mask_filename);
% Load volume eigenmodes
eigenmodes_filename = sprintf('data/examples/hcp_%s-%s_emode_30_noconstant_zscore.nii.gz', structure, hemisphere);
% Replace above line with the one below if using the modes provided at data/results
% eigenmodes_filename = sprintf('data/results/hcp_%s-%s_emode_30_noconstant_zscore.nii.gz', structure, hemisphere);
V_eigenmodes = niftiread(eigenmodes_filename);
% =========================================================================
% Visualize one eigenmode
% =========================================================================
% In this example, the 1st eigenmode
mode_interest = 1;
camera_view = [-27.5, 40]; % good camera view for striatum is [-61.5, 27] and hippocampus is [41, 43]
markersize = 80;
volume_to_plot = V_mask;
data_to_plot = V_eigenmodes(:,:,:,mode_interest);
fig = draw_volume_bluewhitered(volume_to_plot, data_to_plot, camera_view, markersize);
fig.Name = sprintf('Single volume eigenmode (mode = %i)', mode_interest);
% =========================================================================
% Visualize multiple eigenmodes
% =========================================================================
% In this example, the 1st to 5th eigenmodes
mode_interest = [1:5];
camera_view = [-27.5, 40]; % good camera view for striatum is [-61.5, 27] and hippocampus is [41, 43]
markersize = 80;
volume_to_plot = V_mask;
data_to_plot = V_eigenmodes(:,:,:,mode_interest);
fig = draw_volume_bluewhitered_gallery(volume_to_plot, data_to_plot, camera_view, markersize);
fig.Name = 'Multiple volume eigenmodes';