-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsunvs_gen_centroid_coor.m
46 lines (40 loc) · 1.44 KB
/
sunvs_gen_centroid_coor.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
function [CenCoor] = sunvs_gen_centroid_coor(Path_gifti, Path_annot)
%==========================================================================
% This function is used to calculate centroid coordination included of each ROI
% in a gifti image, where the ROIs are defined by an annot file.
%
%
% Syntax: function [CenCoor] = sunvs_gen_centroid_coor(Path_filename, Path_annot)
%
% Input:
% Path_filename:
% The directory & filename of a gifti file, this gifti file defines
% the shape of the surface.
% Path_annot:
% The directory & filename of a template annot file, the annot file
% is an atlas file which defines ROIs.
%
% Output:
% CenCoor:
% The centroid coordination of each ROI.
%
% Ningkai WANG,IBRR, SCNU, Guangzhou, 2020/01/24, [email protected]
%==========================================================================
g = gifti(Path_gifti);
Vertices = double(g.vertices);
if nargin == 1
c = double(g.cdata);
Label_region = unique(c(~isnan(c)));
Num_regs = max(Label_region);
elseif nargin == 2
[~, Label, Colortable] = read_annotation(Path_annot);
Label_region = Colortable.table(2:end, 5);
Num_regs = length(Label_region);
end
CenCoor = zeros(Num_regs,3);
for i_roi = 1:Num_regs
Ind_roi = Label_region(i_roi);
Index = Label == Ind_roi;
CenCoor(i_roi,:) = mean(Vertices(Index,:), 1);
end
end