-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrsHRF_check_ROI.m
111 lines (107 loc) · 3.62 KB
/
rsHRF_check_ROI.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
function [mat,atlas,nii,atlasmesh,gii]= rsHRF_check_ROI(ROI, funii, flag_delete)
mat = {}; atlas = {}; nii = {}; atlasmesh = {}; gii = {};
k1 =1 ; k2 = 1; k3 = 1; k4 = 1; k5 = 1;
for i=1:length(ROI)
tmp = ROI{i};
flag = isfield(tmp,'ROI');
if flag
for j=1: size(tmp.ROI,1)
tmp2 = tmp.ROI(j,:);
xY = [];
xY.def='sphere';
xY.xyz=tmp2(1:3)';
xY.spec=tmp2(4);
[xY, XYZmm, id] = spm_ROI(xY, funii);
if isempty(id)
error(sprintf('\n\n====(ROI)Error Information====\nno voxel found in sphere with center (%3.1f, %3.1f, %3.1f) and radius %3.1f.\nTry to increase the radius???\n',tmp2));
else
fprintf('#%d voxels found in sphere with center (%3.1f, %3.1f, %3.1f) and radius %3.1f.\n',length(id),tmp2)
end
mat{k1,1} = id;
mat{k1,2} = tmp2;
mat{k1,3} = '';
k1 = k1+1;
continue;
end
end
flag = isfield(tmp,'atlas');
if flag
for j=1: length(tmp.atlas)
tmp2 = strcat(tmp.atlas{j});
if ~isempty(tmp2)
atlas{k2,1} = tmp2;
niinew = spm_file(tmp2,'prefix','bin_');
spm_imcalc({funii;tmp2},niinew,'(i1~=0).*i2',{0,0,0,16});
v = spm_vol(niinew);
datam = spm_read_vols(v); datam(isnan(datam)) = 0;
idu = unique(datam(:)); idu(idu==0)=[];
for k=1:length(idu)
atlas{k2,1} = find(datam==idu(k));
atlas{k2,2} = tmp2;
atlas{k2,3} = idu(k);
k2 = k2+1;
end
clear datam
if flag_delete
delete(v.fname)
end
end
end
continue;
end
flag = isfield(tmp,'images');
if flag
for j=1: length(tmp.images)
tmp2 = strcat(tmp.images{j});
if ~isempty(tmp2)
nii{k3,1} = tmp2;
niinew = spm_file(tmp2,'prefix','bin_');
spm_imcalc({funii;tmp2},niinew,'(i1~=0).*i2',{0,0,0,16});
v =spm_vol(niinew);
datam = spm_read_vols(v);
nii{k3,1} = find(datam); clear datam
nii{k3,2} = tmp2;
nii{k3,3} = '';
if flag_delete
delete(v.fname)
end
k3 = k3+1;
end
end
continue;
end
flag = isfield(tmp,'meshmask');
if flag
for j=1: length(tmp.meshmask)
tmp2 = strcat(tmp.meshmask{j});
if ~isempty(tmp2)
gii{k4,1} = tmp2;
datam = gifti(tmp2);
gii{k4,1} = find(datam.cdata); clear datam
gii{k4,2} = tmp2;
gii{k4,3} = '';
k4 = k4+1;
end
end
continue;
end
flag = isfield(tmp,'meshatlas');
if flag
for j=1: length(tmp.meshatlas)
tmp2 = strcat(tmp.meshatlas{j});
if ~isempty(tmp2)
atlasmesh{k5,1} = tmp2;
datam = gifti(tmp2);
idu = unique(datam.cdata(:)); idu(idu==0)=[];
for k=1:length(idu)
atlasmesh{k5,1} = find(datam.cdata==idu(k));
atlasmesh{k5,2} = tmp2;
atlasmesh{k5,3} = idu(k);
k5 = k5+1;
end
clear datam
end
end
continue;
end
end