forked from bblonder/thermal_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matlab_capture.m
executable file
·198 lines (170 loc) · 8.53 KB
/
matlab_capture.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
nuc_count_last = 0;
nuc_temp_sd_last = 0;
nuc_count_max = 50; % max number of tries to fix NUC
nuc_sd_min = 0.5; % minimum temperature s.d. in degC to allow NUC to pass
num_failed_frames_max = 10;
options = {'Camera setup', 'Camera close','AutoFocus','FocusManual','NUC','Snapshots'};
done = 0;
while ~done
action = listdlg('PromptString','Choose an action','SelectionMode','single','ListString', options, 'ListSize',[200 200],'InitialValue',3);
if isempty(action)
done = 1;
else
switch(action)
case 1
try
g = gigecam(1);
for index=1:10
% do some cycling to force the mode
g.IRFormat='Radiometric';
g.IRFormat='TemperatureLinear10mK'; %'Radiometric'
w = snapshot(g);
pause(0.5);
fprintf('.');
end
g.TSensSelector='Lens';
g.NoiseReduction='On';
g.AutoFocusMethod='Fine';
g.NUCMode = 'Off';
executeCommand(g, 'AutoFocus');
pause(1);
fprintf('Focus distance: %f\n', g.FocusDistance);
[img, ts] = snapshot(g);
imagesc(double(img)*10/1000-273.15); colorbar;
catch
warning('could not open camera');
end
case 2
try
clear g;
done = 1;
catch
warning('could not close camera');
end
case 3
try
executeCommand(g, 'AutoFocus');
pause(3);
fprintf('Focus distance: %f\n', g.FocusDistance);
[img, ts] = snapshot(g);
imagesc(double(img)*10/1000-273.15); colorbar;
catch
warning('could not focus');
end
case 4
try
prompt = {'Focus distance (m approx)'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {sprintf('%.4f',g.FocusDistance)};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
focus_dist_new = str2num(answer{1});
g.FocusDistance = focus_dist_new;
fprintf('Focus distance: %f\n', g.FocusDistance);
pause(0.1);
[img, ts] = snapshot(g);
imagesc(double(img)*10/1000-273.15); colorbar;
catch
warning('Manual focus or snapshot failed');
end
case 5
try
[nuc_count, sd_temp_degc] = nuc_count_repeated(g, nuc_sd_min, nuc_count_max);
fprintf('Image SD (degC): %.3f\n',sd_temp_degc);
nuc_count_last = nuc_count;
nuc_temp_sd_last = sd_temp_degc;
catch
warning('NUC failed');
end
case 6
prompt = {'Frame interval (sec):','Number of frames:','NUC Interval (# frames)','File prefix:'};
dlg_title = 'Input (set Number of frames=0 for continuous logging)';
num_lines = 1;
defaultans = {'5','0','0','test'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
frame_interval = str2num(answer{1});
frame_count = str2num(answer{2});
nuc_frame_interval = str2num(answer{3});
file_prefix = answer{4};
% set home directory as path
selpath = uigetdir('~','Choose a directory');
all_frames_done = 0;
i = 0;
num_failed_frames = 0;
while (~all_frames_done)
try
g.IRFormat='TemperatureLinear10mK';
[img, ts] = snapshot(g);
imagesc(double(img)*10/1000-273.15); colorbar;
time_str = datestr(now,'yymmdd-HHMMSS');
save(fullfile(selpath,sprintf('snapshot_%s_%s_matrix_tlinear.mat',file_prefix, time_str)),'img');
%imwrite(255*rescale_image_quantile(double(img), 0.0, 1.0),parula(255), fullfile(selpath,sprintf('snapshot_%s_%s_image_tlinear.png',file_prefix, time_str)));
imwrite(255*rescale_image_range(double(img)*10/1000-273.15, 10, 40),parula(255), fullfile(selpath,sprintf('snapshot_%s_%s_image_tlinear.png',file_prefix, time_str)));
%imwrite(img,fullfile(selpath, sprintf('snapshot_%s_%s_image_tlinear.tif',file_prefix, time_str)));
% grab radiometric frames for later calibration
% purposes
g.IRFormat='Radiometric';
pause(1);
for j=1:10 % burn some frames to clear the buffer
[img_rm, ts] = snapshot(g);
end
save(fullfile(selpath,sprintf('snapshot_%s_%s_matrix_radiometric.mat',file_prefix, time_str)),'img_rm');
imwrite(255*rescale_image_quantile(double(img_rm), 0.0, 1.0),parula(255), fullfile(selpath,sprintf('snapshot_%s_%s_image_radiometric.png',file_prefix, time_str)));
%imwrite(img_rm,fullfile(selpath,sprintf('snapshot_%s_%s_image_radiometric.tif',file_prefix, time_str)));
% return to tlinear mode
g.IRFormat='TemperatureLinear10mK';
pause(frame_interval);
% on-screen diagnostic
fprintf('%d %s\n', i, time_str);
% write a log
fileID = fopen(fullfile(selpath, sprintf('snapshot_%s_%s_log.txt',file_prefix, time_str)),'w');
fprintf(fileID,'nuc_count_last\t%d\n',nuc_count_last);
fprintf(fileID,'nuc_temp_sd_last\t%.4f\n',nuc_temp_sd_last);
fprintf(fileID,'TSens\t%.4f\n',g.TSens);
fclose(fileID);
% do a NUC if desired
if (nuc_frame_interval > 0)
if (mod(i, nuc_frame_interval) == 0)
[nuc_count, sd_temp_degc] = nuc_count_repeated(g, nuc_sd_min, nuc_count_max);
nuc_count_last = nuc_count;
nuc_temp_sd_last = sd_temp_degc;
end
end
% iterate
i=i+1;
if (frame_count > 0)
all_frames_done = (i>=frame_count);
else
all_frames_done = 0;
end
% restart camera if needed
if (num_failed_frames > num_failed_frames_max)
try
clear g;
pause(0.5);
g = gigecam(1);
for index=1:10
% do some cycling to force the mode
g.IRFormat='Radiometric';
g.IRFormat='TemperatureLinear10mK'; %'Radiometric'
w = snapshot(g);
pause(0.5);
fprintf('.');
end
g.TSensSelector='Lens';
g.NoiseReduction='On';
g.AutoFocusMethod='Fine';
g.NUCMode = 'Off';
num_failed_frames = 0;
catch
warning('Restarting camera');
end
end
catch
warning('image frame failed (%d in a row)',num_failed_frames);
num_failed_frames = num_failed_frames + 1;
end
end
end
end
end