-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGetA0.m
52 lines (48 loc) · 1.28 KB
/
GetA0.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
function a0 = GetA0(z,Wa,mu)
% Compute mean plus linear combination of appearance bases
% FORMAT a0 = GetA0(z,Wa,mu)
%
% z - Latent variables (weights for linear combination)
% Wa - Appearance basis functions
% mu - Appearance mean
% a0 - mean plus linear combination of appearance basis functions
%
% If z is a cell array of vectors, a0 will be a cell array of
% the corresponding images.
%__________________________________________________________________________
% Copyright (C) 2017 Wellcome Trust Centre for Neuroimaging
% John Ashburner
% $Id$
d = [size(Wa) 1 1 1];
d = d(1:5);
if ~iscell(z) % z is a vector
if nargin<3
a0 = zeros(d(1:4),'single');
else
a0 = mu;
end
for k=1:d(5)
a0 = a0 + Wa(:,:,:,:,k)*z(k);
end
else % z is a cell array
a0 = cell(size(z));
if nargin<3
% Create one volume and copy it. May save memory.
a0{1} = zeros(d(1:4),'single');
for n=2:numel(a0)
a0{n} = a0{1};
end
else
% Create one volume and copy it. May save memory.
a0{1} = mu(:,:,:,:);
for n=2:numel(a0)
a0{n} = a0{1};
end
end
for k=1:d(5)
Wk = Wa(:,:,:,:,k);
for n=1:numel(a0)
a0{n} = a0{n} + Wk*z{n}(k);
end
end
end