-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.m
113 lines (86 loc) · 2.49 KB
/
example.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
clc
clearvars
%% add current directory
addpath(genpath(pwd))
%% read in some data
% inf_surf_lh = './example_data/lh.inflated' ;
inf_surf_rh = './example_data/rh.inflated' ;
% annot_lh = './example_data/lh.YeoUpsample.annot' ;
annot_rh = './example_data/rh.YeoUpsample.annot' ;
[~,annotLabs,annotTable] = read_annotation(annot_rh) ;
[verts,faces] = read_surf(inf_surf_rh);
%% get the neigbors
s = struct() ;
s.nverts = size(verts,1) ;
s.nfaces = size(faces,1) ;
s.faces = faces + 1 ;
s.coords = verts ;
n = fs_find_neighbors(s) ;
%% load the annotation file
w = ones(length(annotLabs),1);
for idx = 1:size(annotTable.table,1)
disp(idx)
w(annotLabs == annotTable.table(idx,5)) = idx;
end
%% viz the labels pre-dilation
figure
colormap(annotTable.table(:,1:3) ./ 255)
RH = trisurf(s.faces,...
s.coords(:,1),...
s.coords(:,2),...
s.coords(:,3),...
w);
set(RH,'EdgeColor','none');
axis equal; axis off
view(90,0)
camlight headlight; material dull; lighting gouraud
RH.CDataMapping = 'direct' ;
%% dilate surface based on neighbors
% function [ dil_vert_weights ] = dil_surf_parc(vert_weights,nbrs,gap_wei,nbrs_size)
w_dil = dil_surf_parc(w,n.nbrs,1,2) ;
fin = 0 ;
idx = 1 ;
while ~fin
disp(idx)
idx = idx + 1;
[w_dil,fin] = dil_surf_parc(w_dil,n.nbrs,1,2) ;
end
%% viz the labels after dilation
figure
colormap(annotTable.table(:,1:3) ./ 255)
RH = trisurf(s.faces,...
s.coords(:,1),...
s.coords(:,2),...
s.coords(:,3),...
w_dil);
set(RH,'EdgeColor','none');
axis equal; axis off
view(90,0)
camlight headlight; material dull; lighting gouraud
RH.CDataMapping = 'direct' ;
%% dil only a couple of times
% function [ dil_vert_weights ] = dil_surf_parc(vert_weights,nbrs,gap_wei,nbrs_size)
w_dil_less = dil_surf_parc(w,n.nbrs,1,2) ;
w_dil_less = dil_surf_parc(w_dil_less,n.nbrs,1,2) ;
figure
colormap(annotTable.table(:,1:3) ./ 255)
RH = trisurf(s.faces,...
s.coords(:,1),...
s.coords(:,2),...
s.coords(:,3),...
w_dil_less);
set(RH,'EdgeColor','none');
axis equal; axis off
view(90,0)
camlight headlight; material dull; lighting gouraud
RH.CDataMapping = 'direct' ;
%% note
% in this example, the labels are dilated into the medial wall, which is
% probably what you dont want. to remedy this. you should throw together
% some code like this:
%
% setenv('SUBJECTS_DIR',pwd)
% sname = 'fsaverage' ;
% lname = 'rh.Medial_wall' ;
% rh_medial_wall = read_label(sname,lname) ;
% w_dil(rh_medial_wall(:,1)+1) = 1 ; % or whatever you want the medial wall labeled as