-
Notifications
You must be signed in to change notification settings - Fork 44
/
hmri_create_comm_adjust.m
89 lines (83 loc) · 3.26 KB
/
hmri_create_comm_adjust.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
function [M,R] = hmri_create_comm_adjust(option,Ref,Other,Nits,doshear,Template)
% This function is a version of comm_adjust.m customized for T1 like
% images, i.e. MT images. Now it is necessary to define as input parameter
% the Template to be used for the commisure adjustment.
%
%% Lester Melie-Garcia
% LREN, CHUV.
% Lausanne, December 6th, 2016
if option,
switch nargin
case 1, Nits = 2; doshear = 0;
%Modality = input('modality of image?: ','s');
Ref = myselect(Inf,'image','select file to adust',sel,wd,'.*','1');
Other = myselect(Inf,'image','select other files to adust','',pwd,'.*','1');
if isempty(Other), filenames = Ref; else
filenames = unique(strvcat(Ref,Other),'rows'); %#ok<*FPARK>
end
case 2,
%Modality = input('modality of image?: ','s');
Other = myselect(Inf,'image','select other files to adust','',pwd,'.*','1');
if isempty(Other), filenames = Ref; else
filenames = unique(strvcat(Ref,Other),'rows');
end
case 3, Nits = 2; doshear = 0;
Other = myselect(Inf,'image','select other files to adust','',pwd,'.*','1');
if isempty(Other), filenames = Ref; else
filenames = unique(strvcat(Ref,Other),'rows');
end
case 4, Nits = 2; doshear = 0;
filenames = unique(strvcat(Ref,Other),'rows');
case 5, doshear = 0;
filenames = unique(strvcat(Ref,Other),'rows');
case 6, doshear = logical(doshear);
filenames = unique(strvcat(Ref,Other),'rows');
otherwise, error('too or few inputs!')
end
else
switch nargin
case 2, Nits = 2; doshear = 0; filenames = Ref; %Modality = 'T1';
case 3, Nits = 2; doshear = 0; filenames = Ref;
case 4, Nits = 2; doshear = 0;
filenames = unique(strvcat(Ref,Other),'rows');
case 5, doshear = 0;
filenames = unique(strvcat(Ref,Other),'rows');
case 6, doshear = logical(doshear);
filenames = unique(strvcat(Ref,Other),'rows');
otherwise, error('too or few inputs!')
end
end
sep = 8./[1 2 4*ones(1,Nits)];
%Tmp = sprintf('%s//templates//%s.nii',spm('Dir'),Modality);
if ~exist('Template','var')
Template = fullfile(spm('Dir'),'canonical','avg152T1.nii');
end;
flags = struct('WG' ,[] ,...
'WF' ,[] ,...
'sep' ,8 ,...
'regtype' ,'mni' ,...
'globnorm',0);
VRef = spm_smoothto8bit(spm_vol(Ref),8);
VTmp = spm_smoothto8bit(spm_vol(Template),0);
%VTmp = spm_smoothto8bit(spm_vol(Tmp),0);
VRef.pinfo(1:2,:) = VRef.pinfo(1:2,:)/spm_global(VRef);
VTmp.pinfo(1:2,:) = VTmp.pinfo(1:2,:)/spm_global(VTmp);
[M,scal] = spm_affreg(VTmp,VRef,flags,eye(4));
for i = 2:Nits,
flags.sep = sep(i);
[M,scal] = spm_affreg(VTmp,VRef,flags,M,scal); %VTmp.mat\M*VRef.mat
end
if doshear
R = M;
else
[A,B,C] = svd(M(1:3,1:3)); R = A*C'; %#ok<ASGLU>
R(:,4) = R*(M(1:3,1:3)\M(1:3,4)); R(4,4) = 1;
end
spm_progress_bar('Init',size(filenames,1),'Reorient to AC-PC line','volumes completed');
for i = 1:size(filenames,1),
spm_get_space(deblank(filenames(i,:)),...
R*spm_get_space(deblank(filenames(i,:))));
spm_progress_bar('Set',i);
end
spm_progress_bar('Clear');
end