-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ac_networks.m
91 lines (77 loc) · 2.92 KB
/
get_ac_networks.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
% ____________________________________ %
% %
% get_ac_networks %
% ____________________________________ %
function [c_mask, ac_mask, fc_map, min_max_value, max_min_value] = ...
get_ac_networks(roi, func, thresh)
% This function takes an ROI, calculates its mean timecourse during a
% functional timeseries, and correlates the ROI timecourse with the
% timecourse of every voxel in the brain to output a static functional
% connectivity map of that ROI. It then uses that functional connectivity
% map to create a mask of the regions highly correlated with the ROI. It
% can also create a mask of the regions highly anticorrelated with the ROI.
%
% Inputs
% ______
%
% roi Region of interest mask. A 2D binary matrix of a region of
% interest in the brain.
%
% func Functional timeseries. A 3D matrix in which the first two
% dimensions are space and the third dimension is time.
%
% thresh The percentage of voxels in the brain that are to be added to
% the c_mask and ac_mask matrices.
%
% Outputs
% _______
%
% c_mask Mask of areas highly correlated with ROI. This is a 2D binary
% matrix acquired by separating the top (thresh)% of voxels in
% fc_map
%
% ac_mask Mask of areas anticorrelated with ROI. This is a 2D binary
% matrix acquired by separating the bottom (thresh)% of voxels in
% fc_map
%
% fc_map Functional connectivity map of ROI in func. This is an 2D
% matrix with the same spatial dimensions as func showing the
% correlation between the mean timecourse of ROI and the
% timecourse of every voxel in the brain.
%
% 12/18/16 - Anzar Abbas
roi_tc = get_roi_tc(roi,func);
% Getting the mean timecourse of the ROI
fc_map = zeros(size(roi));
% Predefining one of our output matries
for i = 1:size(func,1)
for j = 1:size(func,2)
if any(func(i,j,:))
% Going through every brain voxel
voxel_tc = func(i,j,:);
% Getting the timecourse of the voxel
x = corrcoef(roi_tc,voxel_tc);
fc_map(i,j) = x(2);
% Calculating the Pearson correlation between the voxel timecourse
% and the ROI timecourse and adding it to fc_map
end
end
end
fc_map_brain = fc_map(fc_map~=0);
% Removing all non-brain voxels from the image and vectorizing it
min_max_value = prctile(fc_map_brain,(100-thresh));
% This is the minimum value in the maximum (thresh)% of voxels
max_min_value = prctile(fc_map_brain,thresh);
% This is the maximum value in the minimum (thresh)% of voxels
c_mask = 1 .* (fc_map > min_max_value);
% Assigning the top (thresh)% of voxels to c_mask
ac_mask = 1 .* (fc_map < max_min_value);
for i = 1:size(ac_mask,1)
for j = 1:size(ac_mask,2)
if fc_map(i,j) == 0
ac_mask(i,j) = 0;
end
end
end
% Assigning the bottom (thresh)% of voxels to ac_mask
end