forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathea_coreg2images.m
87 lines (76 loc) · 2.98 KB
/
ea_coreg2images.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
function affinefile = ea_coreg2images(options,moving,fixed,ofile,otherfiles,writeoutmat,msks,interp)
% Generic function for image coregistration
%
% 1. Moving image will keep untouched unless the output points to the same
% image.
% 2. Use 'ea_backuprestore' before this function in case you want to
% backup/restore the moving image to/from the 'raw_' prefixed image.
% 3. 'otherfiles' will always be overwritten. If you don't want them to be
% overwritten, use 'ea_apply_coregistration' afterwards to apply the
% returned forward transform ('affinefile{1}') to 'otherfiles' rather
% than supply 'otherfiles' parameter here.
if ~exist('otherfiles','var')
otherfiles = {};
elseif isempty(otherfiles) % [] or {} or ''
otherfiles = {};
elseif ischar(otherfiles) % single file, make it to cell string
otherfiles = {otherfiles};
end
if ~exist('writeoutmat','var') || isempty(writeoutmat)
writeoutmat = 0;
end
if ~exist('affinefile','var') || isempty(affinefile)
affinefile = {};
end
if ~exist('msks','var') || isempty(msks)
msks={};
end
if ~exist('interp','var') || isempty(interp)
interp=4;
end
switch options.coregmr.method
case 'SPM' % SPM
affinefile = ea_spm_coreg(options,moving,fixed,'nmi',1,otherfiles,writeoutmat,interp);
[fpth, fname, ext] = ea_niifileparts(moving);
spmoutput = [fileparts(fpth), filesep, 'r', fname, ext];
if ~strcmp(spmoutput, ofile)
movefile(spmoutput, ofile);
end
for ofi=1:length(otherfiles)
[fpth, fname, ext] = ea_niifileparts(otherfiles{ofi});
spmoutput = [fileparts(fpth), filesep, 'r', fname, ext];
movefile(spmoutput, [fpth, ext]);
end
case 'FSL FLIRT' % FSL FLIRT
affinefile = ea_flirt(fixed,...
moving,...
ofile,writeoutmat,otherfiles);
case 'FSL BBR' % FSL BBR
affinefile = ea_flirt_bbr(fixed,...
moving,...
ofile,writeoutmat,otherfiles);
case 'ANTs' % ANTs
affinefile = ea_ants(fixed,...
moving,...
ofile,writeoutmat,otherfiles,msks);
case 'BRAINSFIT' % BRAINSFit
affinefile = ea_brainsfit(fixed,...
moving,...
ofile,writeoutmat,otherfiles);
case 'Hybrid SPM & ANTs' % Hybrid SPM -> ANTs
ea_spm_coreg(options,moving,fixed,'nmi',0,otherfiles,writeoutmat)
affinefile = ea_ants(fixed,...
moving,...
ofile,writeoutmat,otherfiles);
case 'Hybrid SPM & FSL' % Hybrid SPM -> FSL
ea_spm_coreg(options,moving,fixed,'nmi',0,otherfiles,writeoutmat)
affinefile = ea_flirt(fixed,...
moving,...
ofile,writeoutmat,otherfiles);
case 'Hybrid SPM & BRAINSFIT' % Hybrid SPM -> Brainsfit
ea_spm_coreg(options,moving,fixed,'nmi',0,otherfiles,writeoutmat)
affinefile = ea_brainsfit(fixed,...
moving,...
ofile,writeoutmat,otherfiles);
end
% ea_conformspaceto(fixed, ofile); % fix qform/sform issues.