-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_cortical_homogeneity.m
80 lines (68 loc) · 2.4 KB
/
calc_cortical_homogeneity.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
function homogeneity_parcel = calc_cortical_homogeneity(parc, data, metric)
% calc_cortical_parc_metrics.m
%
% Calculate cortical parcellation homogeneity based on the strength of
% within functional connectivity.
%
% Inputs: parc : parcellation [Nx1]
% N = number of vertices
% data : fMRI time series data [NxT]
% T = time points
% metric : performance metric to calculate (string)
% Possible metrics:
% 'mean_zFC' = average of zFC within a parcel
% 'mean_FC' = average of FC within a parcel
%
% Output: homogeneity_parcel : homogeneity value per parcel [num_parcelsx1]
%
% Original: James Pang, Monash University, 2022
%%
if nargin<3
metric = 'mean_FC';
end
num_vertices = size(parc,1);
parcels = unique(parc(parc>0));
num_parcels = length(parcels);
homogeneity_parcel = zeros(num_parcels,1);
size_data = size(data);
for parcel_ind = 1:num_parcels
parcel_interest = parcels(parcel_ind);
ind_parcel = find(parc==parcel_interest);
if size_data(1)==num_vertices
data_parcel = data(ind_parcel,:)';
T = size_data(2);
elseif size_data(2)==num_vertices
data_parcel = data(:,ind_parcel);
T = size_data(1);
end
data_parcel_normalized = calc_normalize_timeseries(data_parcel);
data_parcel_normalized(isnan(data_parcel_normalized)) = 0;
FC = data_parcel_normalized'*data_parcel_normalized;
FC = FC/T;
zFC = atanh(FC);
FC(isnan(FC)) = 0;
zFC(isnan(zFC)) = 0;
if strcmpi(metric, 'mean_zFC')
triu_ind = find(triu(ones(size(zFC)),1));
homogeneity_parcel(parcel_ind) = mean(zFC(triu_ind));
elseif strcmpi(metric, 'mean_FC')
triu_ind = find(triu(ones(size(FC)),1));
homogeneity_parcel(parcel_ind) = mean(FC(triu_ind));
end
end
function data_normalized = calc_normalize_timeseries(data)
% calc_normalize_timeseries.m
%
% Normalize timeseries with respect to mean and std
%
% Input: data : fMRI data [TxN]
% T = length of time
% N = number of points
%
% Output: data_normalized
%
% Original: James Pang, Monash University, 2022
%%
T = size(data,1);
data_normalized = detrend(data, 'constant');
data_normalized = data_normalized./repmat(std(data_normalized),T,1);