-
Notifications
You must be signed in to change notification settings - Fork 3
/
apply_warp.m
152 lines (131 loc) · 5.49 KB
/
apply_warp.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
function [] = apply_warp(image_type,img_fix,img_mov,img_reslice,reg_affine,reg_deform,reg_deform_inv)
% -------------------------------------------------------------------------
% Calls greedy to apply an affine and/or other deformation to a grayscale
% image, label map (segmentation), or vtk mesh.
%
% INPUT:
%
% image_type: 'grayscale', 'label', or 'mesh'
% img_fix: fixed (reference) image filename
% img_reslice: filename of output (warped) image
% reg_affine: filename of affine registration (optional)
% reg_deform: filename of deformation field (optional)
% reg_deform_inv: filename of inverse deformation field (optional)
%
% The optional input arguments determine which parameters are used in the
% call to greedy (affine, deformable registration, or both). Use full
% paths for all filenames.
% -------------------------------------------------------------------------
if ~isempty(reg_affine) && ~isempty(reg_deform) && isempty(reg_deform_inv)
switch image_type
case 'grayscale'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri LINEAR '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform ' ' reg_affine];
case 'label'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri NN '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform ' ' reg_affine];
case 'mesh'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-rs ' mesh_mov ' ' mesh_reslice ' '...
'-r ' reg_deform ' ' reg_affine];
end
system(str);
disp('Affine + deformable transformations applied');
elseif ~isempty(reg_affine) && isempty(reg_deform) && isempty(reg_deform_inv)
switch image_type
case 'grayscale'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri LINEAR '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_affine];
case 'label'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri NN '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_affine];
case 'mesh'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-rs ' img_mov ' ' img_reslice ' '...
'-r ' reg_affine];
end
system(str);
disp('Affine transformation applied');
elseif ~isempty(reg_affine) && isempty(reg_deform) && ~isempty(reg_deform_inv)
switch image_type
case 'grayscale'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri LINEAR '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_affine ',-1 ' reg_deform_inv];
case 'label'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri NN '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_affine ',-1 ' reg_deform_inv];
case 'mesh'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-rs ' img_mov ' ' img_reslice ' '...
'-r ' reg_affine ',-1 ' reg_deform_inv];
end
system(str);
disp('Inverse affine + deformable transformations applied');
elseif isempty(reg_affine) && ~isempty(reg_deform) && isempty(reg_deform_inv)
switch image_type
case 'grayscale'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri LINEAR '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform];
case 'label'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri NN '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform];
case 'mesh'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-rs ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform];
end
system(str);
disp('Deformable transformation applied');
elseif isempty(reg_affine) && isempty(reg_deform) && ~isempty(reg_deform_inv)
switch image_type
case 'grayscale'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri LINEAR '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform_inv];
case 'label'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-ri NN '...
'-rm ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform_inv];
case 'mesh'
str = ['/usr/local/bin/greedy -d 3 '...
'-rf ' img_fix ' ' ...
'-rs ' img_mov ' ' img_reslice ' '...
'-r ' reg_deform_inv];
end
system(str);
disp('Only inverse deformable registration applied');
else
warning('Transforms not properly specified')
end