forked from Diagonalizable/HelTomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_ct_scan_parameters.m
190 lines (151 loc) · 5.75 KB
/
read_ct_scan_parameters.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
function [ ScanParameters ] = read_ct_scan_parameters(filename)
%READ_CT_SCAN_PARAMETERS Read CT scan parameters from .txt file
% scanParameters = read_ct_scan_parameters(filename) creates a data
% structure containing all the relevant parameters and metadata of a
% computed tomography scan, but no actual projection data. The parameters
% are given in a .txt file specified by the ''filename'', and the .txt
% file itself should be in the format specified by the file
% 'ct_scan_parameters_template.txt'.
%
% All measures of distance in the CT scan parameters are given in
% millimeters, and all angles are in degrees.
%
% This function is part of the HelTomo Toolbox, and was created primarily
% for use with CT data measured in the Industrial Mathematics Computed
% Tomography Laboratory at the University of Helsinki.
%
% Alexander Meaney, University of Helsinki
% Created: 28.1.2019
% Last edited: 2.8.2022
% Verify that the filename given specifies a .txt file
[~, ~, ext] = fileparts(filename);
if ~strcmp(ext, '.txt')
error('Input must be a .txt file.')
end
% Read raw data from file
f = fopen(filename, 'r');
rawData = textscan(f, '%s %s', 'delimiter', '=');
fclose(f);
% Create Map from raw data
dataMap = containers.Map(strtrim(rawData{1}), strtrim(rawData{2}));
% Create a struct for the scan parameter data
ScanParameters = struct;
% Read parameters from Map and enter into struct, converting into the
% suitable data type when necessary. Some scan parameters are compulsory
% information for CT reconstruction, in which case their presence is
% checked.
if isKey(dataMap, 'ProjectName')
ScanParameters.projectName = dataMap('ProjectName');
else
error('Compulsory field ''ProjectName'' missing in scan parameter file.');
end
if isKey(dataMap, 'Scanner')
ScanParameters.scanner = dataMap('Scanner');
end
if isKey(dataMap, 'Measurers')
ScanParameters.measurers = dataMap('Measurers');
end
if isKey(dataMap, 'Date')
ScanParameters.date = dataMap('Date');
end
if isKey(dataMap, 'DateFormat')
ScanParameters.dateFormat = dataMap('DateFormat');
end
if isKey(dataMap, 'GeometryType')
ScanParameters.geometryType = dataMap('GeometryType');
else
error('Compulsory field ''GeometryType'' missing in scan parameter file.');
end
if isKey(dataMap, 'DistanceSourceDetector')
ScanParameters.distanceSourceDetector = str2double(dataMap('DistanceSourceDetector'));
else
error('Compulsory field ''DistanceSourceDetector'' missing in scan parameter file.');
end
if isKey(dataMap, 'DistanceSourceOrigin')
ScanParameters.distanceSourceOrigin = str2double(dataMap('DistanceSourceOrigin'));
else
error('Compulsory field ''DistanceSourceOrigin'' missing in scan parameter file.');
end
if isKey(dataMap, 'DistanceUnit')
ScanParameters.distanceUnit = dataMap('DistanceUnit');
end
% Compute new geometric data field from data and add to scan parameters
ScanParameters.geometricMagnification = ...
ScanParameters.distanceSourceDetector / ...
ScanParameters.distanceSourceOrigin;
if isKey(dataMap, 'NumberImages')
ScanParameters.numberImages = str2double(dataMap('NumberImages'));
else
error('Compulsory field ''NumberImages'' missing in scan parameter file.');
end
% Compute angle information and add to scan parameters
if isKey(dataMap, 'AngleFirst')
angleFirst = str2double(dataMap('AngleFirst'));
else
error('Compulsory field ''AngleFirst'' missing in scan parameter file.');
end
if isKey(dataMap, 'AngleInterval')
angleInterval = str2double(dataMap('AngleInterval'));
else
error('Compulsory field ''AngleInterval'' missing in scan parameter file.');
end
if isKey(dataMap, 'AngleLast')
angleLast = str2double(dataMap('AngleLast'));
else
error('Compulsory field ''AngleLast'' missing in scan parameter file.');
end
angles = angleFirst : angleInterval : angleLast;
ScanParameters.angles = angles;
if isKey(dataMap, 'Detector')
ScanParameters.detector = dataMap('Detector');
end
if isKey(dataMap, 'DetectorType')
ScanParameters.detectorType = dataMap('DetectorType');
else
error('Compulsory field ''DetectorType'' missing in scan parameter file.');
end
if isKey(dataMap, 'Binning')
ScanParameters.binning = dataMap('Binning');
end
if isKey(dataMap, 'PixelSize')
ScanParameters.pixelSize = str2double(dataMap('PixelSize'));
else
error('Compulsory field ''PixelSize'' missing in scan parameter file.');
end
if isKey(dataMap, 'PixelSizeUnit')
ScanParameters.pixelSizeUnit = str2double(dataMap('PixelSizeUnit'));
end
if isKey(dataMap, 'ExposureTime')
ScanParameters.exposureTime = dataMap('ExposureTime');
end
if isKey(dataMap, 'ExposureTimeUnit')
ScanParameters.exposureTimeUnit = dataMap('ExposureTimeUnit');
end
if isKey(dataMap, 'Tube')
ScanParameters.tube = dataMap('Tube');
end
if isKey(dataMap, 'Target')
ScanParameters.target = dataMap('Target');
end
if isKey(dataMap, 'Voltage')
ScanParameters.voltage = dataMap('Voltage');
end
if isKey(dataMap, 'VoltageUnit')
ScanParameters.voltageUnit = dataMap('VoltageUnit');
end
if isKey(dataMap, 'Current')
ScanParameters.current = dataMap('Current');
end
if isKey(dataMap, 'CurrentUnit')
ScanParameters.currentUnit = dataMap('CurrentUnit');
end
if isKey(dataMap, 'XRayFilter')
ScanParameters.xRayFilter = dataMap('XRayFilter');
end
if isKey(dataMap, 'XRayFilterThickness')
ScanParameters.xRayFilterThickness = dataMap('XRayFilterThickness');
end
if isKey(dataMap, 'XRayFilterThicknessUnit')
ScanParameters.xRayFilterThicknessUnit = dataMap('XRayFilterThicknessUnit');
end
end