-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm_cpypy.m
163 lines (107 loc) · 4.25 KB
/
mm_cpypy.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function [YpY,Nvox]=mm_cpypy(typeAnal,nbsub,P,Mask,Res,paramsAnal,gsf,K,W)
%- compute y'y (time x time) dispersion matrix.
%- Compute only for the voxels in the mask.
%- Data can be filtered or/and normalized.
%-
%================================================================================
%- Copyright (C) 1997-2002 CEA
%- This software and supporting documentation were developed by
%- CEA/DSV/SHFJ/UNAF
%- 4 place du General Leclerc
%- 91401 Orsay cedex
%- France
%================================================================================
hold=0; % interpolation method
sub = 1; % subject 1
[dimt tmp] = size(P{1}); % temporal dimension
Nvox = 0;
%====================================================================
YpY = zeros(dimt);
memchunk = 2^24; %chunk size
sizeVox = ceil((memchunk/(dimt/16))); % 8 = sizeof(double)
for sub=1:nbsub
fprintf('reading data for subject %03d\n',sub);
Nvox(sub)=0;
V = spm_vol(char(P{sub}));
%- Normalisation by the scaling factor, if needed
%--------------------------------------------------------------------
sf=gsf{sub}; %scaling factor for the subject sub
for v=1:dimt
V(v,1).pinfo(1:2,:) = V(v,1).pinfo(1:2,:)*sf(v,1);
end
Vm = spm_vol(Mask{sub}); % Map Mask data
Vr=spm_vol(Res{sub}); % Map Res data
%compute mean spm_MskMean
nbp = sizeVox/prod(V(1).dim(1:2));
nbp = min(max(1,round(nbp)),V(1).dim(3));
all_nbp=length(1:nbp:V(1).dim(3));
for p = 1:nbp:V(1).dim(3)
% lire le mask pour le chunk p dans plm
% lire les residu pour le chunk p dans plr
%---------------------------------------
nb_plan = min(p+nbp,V(1).dim(3)) - p + 1;
plank=length(p:min(p+nbp,V(1).dim(3)));
dimx=V(1).dim(1);
dimy=V(1).dim(2);
fprintf('\r%-20s: ',sprintf('Plane %3d/%-3d ',...
p,V(1).dim(3)))
plm = zeros(dimx*dimy,nb_plan);
plr = zeros(dimx*dimy,nb_plan);
i_plm = 0;
fprintf('%20s',' Reading Mask ');
for ip=p:min(p+nbp,V(1).dim(3))
i_plm = i_plm + 1;
fprintf('%-20s\n',sprintf('plank %3d/%-3d',i_plm,plank))
% fprintf('%s',sprintf('\b')*ones(1,20))
Ma = spm_matrix([0 0 ip]);
iplm = spm_slice_vol(Vm,Ma,Vm.dim(1:2),hold);
plm(:,i_plm) = iplm(:);
iplr = spm_slice_vol(Vr,Ma,Vr.dim(1:2),hold);
plr(:,i_plm) = iplr(:);
end
plm = plm(:) > 0;
plr = plr(:);
nvox = sum(plm); % number of voxel
Nvox(sub) = Nvox(sub) + nvox;
if nvox
% boucle sur les temps
%fprintf('%s',sprintf('\b')*ones(1,20))
fprintf('%20s',' Reading data ')
Y = zeros(floor(nvox),dimt);
for t = 1:dimt
pld = zeros(dimx*dimy,nb_plan);
i_plm = 0;
for ip=p:min(p+nbp,V(1).dim(3))
i_plm = i_plm + 1;
fprintf('%-20s',sprintf('plank %3d/%-3d',...
i_plm,plank))
fprintf('%s',repmat(sprintf('\b'),1,20))
Ma = spm_matrix([0 0 ip]);
ipld = spm_slice_vol(V(t),Ma,V(t).dim(1:2),hold);
pld(:,i_plm) = ipld(:);
end
pld = pld(:);
Y(:,t) = pld(plm);
end % for t = 1:dimt
if paramsAnal.temporalFilter
%fprintf('%s',sprintf('\b')*ones(1,20))
fprintf('%20s',' apply filter ');
Y = (spm_filter(K,W*Y'))';
%fprintf('%s',sprintf('\b')*ones(1,20))
end
if paramsAnal.divideByRessd
%fprintf('%s',sprintf('\b')*ones(1,20))
fprintf('%20s',' divide by Ressd ');
Y = Y./repmat(sqrt(plr(find(plm))),1,dimt);
fprintf('%s',sprintf('\b')*ones(1,20))
end
%fprintf('%s',sprintf('\b')*ones(1,20))
fprintf('%20s',' transposing ');
% YpY = spm_atranspa(real(Y)) + YpY;
YpY =Y'*Y+ YpY;
%fprintf('%s',sprintf('\b')*ones(1,20))
end %if nvox
end % for p = 1:nbp:V(1).dim(3):
end % for sub=1:nbsub
%fprintf('%s',sprintf('\b')*ones(1,60))
%fprintf('%s\r',sprintf(' ')*ones(1,80))