-
Notifications
You must be signed in to change notification settings - Fork 0
/
real_time_GIWAXS_movie_generator.m
301 lines (301 loc) · 14.3 KB
/
real_time_GIWAXS_movie_generator.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
%**************************************************************************
% GIWAXS evaluation
%**************************************************************************
clear all
%**************************************************************************
% read calibration text file
%**************************************************************************
path_to_calib_file='d:\laboratory\calibration.txt';
% read calibration text file
calib_info=readtable(path_to_calib_file, 'Delimiter', ' ', 'Format', '%s%u%u%f%f%f%f%u%u%u%f%f%f%f%f%f');
% type of detector
type_of_detector=char(table2array(calib_info(1,1)));
% image dimension
image_dimension=[table2array(calib_info(1,2)), table2array(calib_info(1,3))];
% pixel size
pixel_size=[table2array(calib_info(1,4)), table2array(calib_info(1,5))];
% X-ray energy
E=table2array(calib_info(1,6)); % [keV]
% X-ray wavelength
lambda=1.24/E; % [nm]
% Sample to detector distance
SDD=table2array(calib_info(1,7)); % [in pixels]
% geometry, 1 for transmission, 2 for reflection
geometry=table2array(calib_info(1,8));
% PhiMode, 1 for [-180°, 180°], 2 for [0°, 360°], 3 for [-270°, 90°], 4 for [-90°, 270°]
phi_mode=table2array(calib_info(1,9));
% PolarizationMode, 1, 2, 3, 4 for none, horiozntal, vertical, unpolarized
polarization_mode=table2array(calib_info(1,10));
% horizontal polarization fraction, 1 for fully horizontally polarized beam,
% 0 for fully vertically polarized beam
horizontal_polarization_fraction=table2array(calib_info(1,11));
% incident angle
incident_angle=table2array(calib_info(1,12)); % [deg]
% Beam0
beam0=[table2array(calib_info(1,13)), table2array(calib_info(1,14))];
% Specular
specular=[table2array(calib_info(1,15)), table2array(calib_info(1,16))];
%**************************************************************************
% root name of image
image_name_root='image';
% number of first image
no_start_image=0;
% number of last image
no_stop_image=400;
% time binning
time_binning=1;
% number of digits
no_digits=5;
% image name extension
image_name_extension='tif';
% path to folder
path_to_folder='d:\folder_with_images\';
% direction of evaluation, forward/backward
direction='forward';
%******************************************************************************
% remove bad pixels, 1 is True, 0 is False
remove_bad_pixels=1;
bad_pixels=[[119, 168]]; % [52 445]
size_bad_pixels=size(bad_pixels);
%**************************************************************************
myVideo = VideoWriter('D:\myVideoAlica.avi', 'Motion JPEG AVI');
open(myVideo);
%**************************************************************************
min_intensity=0; % [Counts]
max_intensity=5; % [Counts]
%**************************************************************************
% reshape parameters
no_of_points_x=400;
no_of_points_y=300;
% q_r minimal value
qr_min=-1.8; % [A-1]
% q_r maximal value
qr_max=1.8; % [A-1]
% q_z minimal value
qz_min=0.0; % [A-1]
% q_z maximal value
qz_max=2.5; % [A-1]
%**************************************************************************
% time constant between successive frames
time_step=100; % [ms]
time_const=time_binning*time_step;
if strcmp(direction, 'forward')
time_actual=no_start_image*time_step;
for index_0=no_start_image:time_binning:no_stop_image
sum_matrix=zeros(no_of_points_y, no_of_points_x);
for index_1=index_0:(index_0+time_binning-1)
%**********************************************************************
% calculate number of digits
%**********************************************************************
number=index_1;
count_digits=0;
if (number == 0)
count_digits=1;
else
while (number > 0)
count_digits=count_digits+1;
number=floor(number/10);
end
end
%**********************************************************************
if (count_digits == no_digits)
image_name_number=int2str(index_1);
else
image_name_number=int2str(index_1);
for index_2=1:(no_digits-count_digits)
image_name_number=strcat('0', image_name_number);
end
end
%**********************************************************************
image_name=strcat(image_name_root, '_', image_name_number, '.', image_name_extension);
%**********************************************************************
path_to_image=strcat(path_to_folder, '\',image_name)
%**************************************************************************
% evaluation script
%**************************************************************************
obj=gixsdata(path_to_image);
obj.Camera=type_of_detector;
obj.PixelSize=pixel_size;
%obj.ImDim=image_dimension;
obj.SDD=SDD;
obj.XEnergy=E;
obj.Geometry=geometry;
obj.PhiMode=phi_mode;
obj.PolarizationMode=polarization_mode;
obj.HorizontalPolarizationFraction=horizontal_polarization_fraction;
obj.Beam0=beam0;
obj.Specular=specular;
obj.IncidentAngle=incident_angle;
%**************************************************************************
obj.ImFile=char(path_to_image);
%**************************************************************************
% remove bad pixels
%**************************************************************************
if (remove_bad_pixels == 1)
image_matrix=obj.RawData;
for index_2=1:size_bad_pixels(1)
image_matrix(bad_pixels(index_2,1), bad_pixels(index_2,2))=0.0;
end
obj.RawData=image_matrix(:,:);
end
%**************************************************************************
obj.PlotAxisLabel = 2;
%**************************************************************************
% Define reshaping parameter for (qz vs qr)
param_reshape.X = 6; % qr
param_reshape.Y = 3; % qz
param_reshape.XNOfPts = no_of_points_x; % number of points for X axis
param_reshape.YNOfPts = no_of_points_y; % number of points for y axis
param_reshape.XRange = [qr_min, qr_max]; % range for x
param_reshape.YRange = [qz_min, qz_max]; % range for y
%**************************************************************************
% reshape
dataflag=2; % 2 for corrected data; 1 for masked rawdata
[x,y,img_reshaped,countdata] = reshape_image(obj,param_reshape,dataflag);
%**************************************************************************
sum_matrix(:,:)=sum_matrix(:,:)+img_reshaped(:,:);
%**************************************************************************
delete(obj);
%**************************************************************************
end
%**************************************************************************
time_actual=time_actual+time_const;
time_to_string=num2str(time_actual);
time_string=strcat(time_to_string, ' ms');
% plot reshaped image
figure
imagesc(x,y,sum_matrix, [min_intensity max_intensity]);
axis ij;
set(gca,'ydir','norm');
xlabel('q_r (A^{-1})');
ylabel('q_z (A^{-1})');
title(time_string);
c=colorbar;
colormap parula;
c.Label.String='Intensity (counts)';
c.Label.FontSize=12;
daspect(gca, [1 1 1]);
%xticks(table2array(current_info(1,7)):qr_step:table2array(current_info(1,8)));
%yticks(table2array(current_info(1,9)):qz_step:table2array(current_info(1,10)));
%**************************************************************************
frame=getframe(gcf);
writeVideo(myVideo, frame);
%**************************************************************************
end
% close video
close(myVideo);
%**************************************************************************
else
if strcmp(direction, 'backward')
time_actual=no_stop_image*time_step;
for index_0=no_stop_image:((-1)*time_binning):no_start_image
sum_matrix=zeros(no_of_points_y, no_of_points_x);
for index_1=index_0:(-1):(index_0-time_binning+1)
%**********************************************************************
% calculate number of digits
%**********************************************************************
number=index_1;
count_digits=0;
if (number == 0)
count_digits=1;
else
while (number > 0)
count_digits=count_digits+1;
number=floor(number/10);
end
end
%**********************************************************************
if (count_digits == no_digits)
image_name_number=int2str(index_1);
else
image_name_number=int2str(index_1);
for index_2=1:(no_digits-count_digits)
image_name_number=strcat('0', image_name_number);
end
end
%**********************************************************************
image_name=strcat(image_name_root, '_', image_name_number, '.', image_name_extension);
%**********************************************************************
path_to_image=strcat(path_to_folder, '\',image_name)
%**************************************************************************
% evaluation script
%**************************************************************************
obj=gixsdata(path_to_image);
obj.Camera=type_of_detector;
obj.PixelSize=pixel_size;
%obj.ImDim=image_dimension;
obj.SDD=SDD;
obj.XEnergy=E;
obj.Geometry=geometry;
obj.PhiMode=phi_mode;
obj.PolarizationMode=polarization_mode;
obj.HorizontalPolarizationFraction=horizontal_polarization_fraction;
obj.Beam0=beam0;
obj.Specular=specular;
obj.IncidentAngle=incident_angle;
%**************************************************************************
obj.ImFile=char(path_to_image);
%**************************************************************************
% remove bad pixels
%**************************************************************************
if (remove_bad_pixels == 1)
image_matrix=obj.RawData;
for index_2=1:size_bad_pixels(1)
image_matrix(bad_pixels(index_2,1), bad_pixels(index_2,2))=0.0;
end
obj.RawData=image_matrix(:,:);
end
%**************************************************************************
obj.PlotAxisLabel = 2;
%**************************************************************************
% Define reshaping parameter for (qz vs qr)
param_reshape.X = 6; % qr
param_reshape.Y = 3; % qz
param_reshape.XNOfPts = no_of_points_x; % number of points for X axis
param_reshape.YNOfPts = no_of_points_y; % number of points for y axis
param_reshape.XRange = [qr_min, qr_max]; % range for x
param_reshape.YRange = [qz_min, qz_max]; % range for y
%**************************************************************************
% reshape
dataflag=2; % 2 for corrected data; 1 for masked rawdata
[x,y,img_reshaped,countdata] = reshape_image(obj,param_reshape,dataflag);
%**************************************************************************
sum_matrix(:,:)=sum_matrix(:,:)+img_reshaped(:,:);
%**************************************************************************
delete(obj);
%**************************************************************************
end
%**************************************************************************
time_actual=time_actual-time_const;
time_to_string=num2str(time_actual);
time_string=strcat(time_to_string, ' ms');
% plot reshaped image
figure
imagesc(x,y,sum_matrix, [min_intensity max_intensity]);
axis ij;
set(gca,'ydir','norm');
xlabel('q_r (A^{-1})');
ylabel('q_z (A^{-1})');
title(time_string);
c=colorbar;
colormap parula;
c.Label.String='Intensity (counts)';
c.Label.FontSize=12;
daspect(gca, [1 1 1]);
%xticks(table2array(current_info(1,7)):qr_step:table2array(current_info(1,8)));
%yticks(table2array(current_info(1,9)):qz_step:table2array(current_info(1,10)));
%**************************************************************************
frame=getframe(gcf);
writeVideo(myVideo, frame);
%**************************************************************************
end
end
%**************************************************************************
% close video
myVideo.FrameRate=2;
close(myVideo);
%******************************************************************************
end
%**************************************************************************
% End
%**************************************************************************