-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspmdefs_get_comp.m
executable file
·48 lines (44 loc) · 1.53 KB
/
spmdefs_get_comp.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
function [Def,mat] = spmdefs_get_comp(job)
% Return the composition of a number of deformation fields.
if isempty(job),
error('Empty list of jobs in composition');
end;
[Def,mat] = get_job(job{1});
for i=2:numel(job),
Def1 = Def;
mat1 = mat;
[Def,mat] = get_job(job{i});
M = inv(mat1);
for j=1:size(Def{1},3)
d0 = {double(Def{1}(:,:,j)), double(Def{2}(:,:,j)),double(Def{3}(:,:,j))};
d{1} = M(1,1)*d0{1}+M(1,2)*d0{2}+M(1,3)*d0{3}+M(1,4);
d{2} = M(2,1)*d0{1}+M(2,2)*d0{2}+M(2,3)*d0{3}+M(2,4);
d{3} = M(3,1)*d0{1}+M(3,2)*d0{2}+M(3,3)*d0{3}+M(3,4);
Def{1}(:,:,j) = single(spm_sample_vol(Def1{1},d{:},[1,NaN]));
Def{2}(:,:,j) = single(spm_sample_vol(Def1{2},d{:},[1,NaN]));
Def{3}(:,:,j) = single(spm_sample_vol(Def1{3},d{:},[1,NaN]));
end;
end;
%_______________________________________________________________________
%_______________________________________________________________________
function [Def,mat] = get_job(job)
% Determine what is required, and pass the relevant bit of the
% job out to the appropriate function.
fn = fieldnames(job);
fn = fn{1};
switch fn
case {'comp'}
[Def,mat] = spmdefs_get_comp(job.(fn));
case {'def'}
[Def,mat] = spmdefs_get_def(job.(fn));
case {'dartel'}
[Def,mat] = spmdefs_get_dartel(job.(fn));
case {'sn2def'}
[Def,mat] = spmdefs_get_sn2def(job.(fn));
case {'inv'}
[Def,mat] = spmdefs_get_inv(job.(fn));
case {'id'}
[Def,mat] = spmdefs_get_id(job.(fn));
otherwise
error('Unrecognised job type');
end;