-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathelastix_paramStruct2txt.m
86 lines (70 loc) · 1.93 KB
/
elastix_paramStruct2txt.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
function elastix_paramStruct2txt(fname,params,verbose)
% Write elastix parameter structure to text file
%
% function elastix_paramStruct2txt(fname,params,verbose)
%
% Write parameter file to fname. Uses default values from this
% file. The output parameters are those produced by a
% registration (e.g. TransformParameters.0.txt). This function
% writes one of these files using a previously imported structure.
%
%
% Rob Campbell - August 2012
%
% Also see: elastix_parameter_read, elastix_parameter_write
if length(params)>1
error('params must have a length of 1')
end
if nargin<3
verbose=false;
end
fprintf('Writing parameter file to %s\n',fname)
fid=fopen(fname,'w+');
R=fields(params);
for ii=1:length(R)
param=R{ii};
value=params.(R{ii});
if isempty(value) %Allows for a value to not be written
continue
end
if ischar(value)
value = strrep(value,'\','\\');
str = sprintf('(%s "%s")\n',param,value);
fprintf(fid,str);
if verbose
fprintf(str)
end
continue
end
if isnumeric(value)
if mod(value(1),1)==0
str = sprintf(['(%s',repmat(' %d',1,length(value)), ')\n'], param, value);
fprintf(fid,str);
if verbose
fprintf(str)
end
continue
elseif mod(value(1),1)>0
str = sprintf(['(%s',repmat(' %2.6f',1,length(value)), ')\n'],param,value);
fprintf(fid,str);
if verbose
fprintf(str)
end
continue
end
end
if islogical(value)
if value
str = sprintf('(%s "true")\n',param);
else
str = sprintf('(%s "false")\n',param);
end
fprintf(fid,str);
if verbose
fprintf(str)
end
continue
end
fprintf('elastix_paramStruct2txt did not write param %s\n', param)
end
fclose(fid);