This repository has been archived by the owner on Jun 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_viewer.m
352 lines (294 loc) · 9.25 KB
/
simple_viewer.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
% SIMPLE_VIEWER.M A simple player for HAUV/DIDSON datasets.
%
% Pedro Vaz Teixeira (PVT), May 2014
% pvt@mit.edu
clc;
close all;
% Curtiss, March 2014
%data = open('log-2014-03-05.01-short.mat');
%data = open('didson-air.mat'); % somwhat useful to get noise properties
% NO TARGETS
%data = open('didson-tank-wall.mat');
%data = open('didson-tank-wall-angle.mat');
%data = open('didson-tank-corner.mat');
%didson-tank-supposedly-nothing
%didson-tank-supposedly-nothing-rust-pump-off
%didson-tank-supposedly-nothing-rust-pump-off-2
%didson-tank-wall-nothing-3
%didson-tank-wall-2
% Fishing line
%data = open('didson-tank-wall-fishing-line.mat');
%data = open('didson-tank-wall-fishing-line-moving.mat');
% Tubes & rods
%data = open('didson-tank-wall-hollow-tube-tilted.mat');
%data = open('didson-tank-wall-aluminum-rod-moving.mat');
%didson-tank-wall-aluminum-rod
data = open('didson-tank-wall-thin-hollow-al-rod.mat');
%data = open('didson-tank-wall-thin-hollow-al-rod-2.mat');
%data = open('didson-tank-wall-thin-hollow-al-rod-moving.mat');
% TUNA CAN!
%data = open('didson-tank-wall-tuna-can.mat');
%data = open('didson-tank-wall-tuna-can-moving-can.mat');
%data = open('didson-tank-wall-tuna-can-moving-hauv.mat');
data = data.data;
% DATA FIELDS
% time:
% data.time - the current date and time [year month day hours minutes seconds]
% data.u_time - vehicle time (in UNIX time)
%
% poses: [ x y z yaw pitch roll ]
% data.sonar_pose - the sonar's pose (in the platform frame)
% data.vehicle_pose - % the vehicle's pose (in the global frame)
%
% sonar data:
% data.frame - the sonar data
% data.gain - the sonar gain used for a particular frame
message_count = size(data.vehicle_pose,2);
pose = cell2mat(data.vehicle_pose); % collapse onto an array.
PSF = zeros(96, 96, message_count);
plot_rows = 1;
plot_columns = 9;
figure();
for i=1:message_count;
tic
num_plot = 1;
% position
%{
subplot(plot_rows,plot_columns,1:2);
plot3(pose(1,1:i), pose(2,1:i), -pose(3,1:i),'-b.');
axis equal;
xlabel('x [m]');
ylabel('y [m]');
zlabel('z [m]');
title('Vehicle position');
%}
frame_polar = flipud(double(data.frame{i})./255);
%% display raw data
% sonar - polar, raw
%
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(frame_polar);
xlabel('Azimuth');
ylabel('Range');
title('Sonar (polar, raw)');
%}
% sonar - polar, raw, normalized
%{
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow((1/max(max(frame_polar)))*frame_polar);
xlabel('Azimuth');
ylabel('Range');
title('Sonar (polar, raw)*');
%}
%% enhance.m tests (mostly transmission loss)
% sonar - polar, enhanced
%
frame_polar_enhanced = enhance(frame_polar, data.window_start{i}, data.window_start{i} + data.window_length{i});
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(frame_polar_enhanced);
title('Sonar (polar, enhanced)');
%}
% sonar - polar, enhanced, normalized
%{
subplot(plot_rows,plot_columns,4);
imshow((1/max(max(frame_polar_enhanced)))*frame_polar_enhanced);
title('Sonar (polar, enhanced)*');
%}
%% Wiener deconvolution (single lobe)
%{
PSF = zeros(1,96);
PSF(1,[1 9 17 25 33 41 49 57 65 73 81 89]) =[ 20 20 20 20 20 20 70 20 20 20 20 20];
PSF = (1/sum(sum(PSF)))*PSF;
% subplot(1,N_plots,2); imshow(50*PSF)
% title('PSF');
% restore assuming no noise
estimated_nsr = 0;
wnr2 = deconvwnr(frame_polar, PSF, estimated_nsr);
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(wnr2)
title('Restoration using NSR = 0')
% restore with noise
estimated_nsr = 0.0018; % replace with experimentally determined value
wnr3 = deconvwnr(frame_polar, PSF, estimated_nsr);
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(wnr3)
title(['Restoration using NSR=',num2str(estimated_nsr)]);
% normalize
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
wnr3 = (1/max(max(wnr3)))*wnr3;
imshow(wnr3);
title(['Restoration using NSR=',num2str(estimated_nsr),'*']);
%}
%% Wiener deconvolution (multiple lobes)
%{
beam = [18,18,18,18,18,18,18,18,24,18,18,18,...
18,18,18,18,24,18,18,18,18,18,18,18,...
27,18,18,18,18,18,18,18,32,18,18,18,...
18,18,18,18,40,18,18,18,28,18,39,18,...
70,18,39,18,28,18,18,18,40,18,18,18,...
18,18,18,18,32,18,18,18,18,18,18,18,...
27,18,18,18,18,18,18,18,24,18,18,18,...
18,18,18,18,24,18,18,18,18,18,18,18];
%}
beam=zeros(1,96);
beam(1,[1 9 17 25 33 41 49 57 65 73 81 89]) =[ 24 24 24 27 32 40 70 40 32 27 24 24];
%beam(2,49) = 60;
%pause
PSF = (1/sum(sum(beam)))*beam;
% restore assuming no noise
%{
estimated_nsr = 0;
wnr4 = deconvwnr(frame_polar, PSF, estimated_nsr);
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(wnr4)
title('Restoration using NSR = 0')
%}
% restore with noise
%{
estimated_nsr = 0.0018; % replace with experimentally determined value (variance)
wnr5 = deconvwnr(frame_polar, PSF, estimated_nsr);
%
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(wnr5)
title(['Restoration using NSR=',num2str(estimated_nsr)]);
%}
% normalize
%{
wnr5 = (1/max(wnr5(:)))*wnr5;
wnr5 = max(frame_polar(:))*wnr5; %correct for same max intensity as the original image
%
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(wnr5);
title(['Restoration using NSR=',num2str(estimated_nsr),'*']);
%}
%{
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(abs(wnr5-wnr3));
%}
%% cartesian
%{
[cart_frame, rx, ry] = polarToCart(frame_polar, data.window_start{i}, data.window_length{i}, 500);
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(cart_frame');
[cart_frame, rx, ry] = polarToCart(wnr5, data.window_start{i}, data.window_length{i}, 500);
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(cart_frame');
%}
%% thresholded image
%{
%wnr5 = max(frame_polar(:))*wnr5;
thr = max(0.5, mean(wnr5(:)) + 3*sqrt(var(wnr5(:))));
hits = im2bw(wnr5, thr); % this may fail as we are working with a normalized image!!
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
imshow(hits);
%}
%% energy content per range
% sonar - average bin intensity
%{
fpbi = zeros(512,1);
fpbid = zeros(512,1);
fpebi = zeros(512,1);
fpebid = zeros(512,1);
for j = 1:512
fpbi(j) = mean(frame_polar(j,:));
fpbid(j) = sqrt(var(frame_polar(j,:)));
fpebi(j) = mean(wnr5(j,:));
fpebid(j) = sqrt(var(wnr5(j,:)));
end
s = mean(fpebi);
dev = sqrt(var(fpebi));
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
%plot(fpbi, 512:-1:1, 'b');
plot(fpbid, 512:-1:1, 'b');
hold on
%
%plot(fpebi+fpebid, 512:-1:1, 'r--');
%plot(fpebi, 512:-1:1, 'r');
plot(fpebid, 512:-1:1, 'r');
plot(wnr5(:,48), 512:-1:1, 'k');
%plot(fpebi-fpebid, 512:-1:1, 'r--');
%plot(fpebid, 512:-1:1, 'b');
%plot([s s], [1 512], 'k');
%plot([s+dev s+dev], [1 512], 'k--');
%plot(max([s-dev s-dev], [0,0]), [1 512], 'k--');
%
hold off
xlim([0 1])
ylim([1 512])
%}
%% energy content per beam
%{
abi = zeros(1,96);
for j=1:96
abi(j) = mean(frame_polar(:,j));
end
subplot(plot_rows,plot_columns,num_plot);
num_plot = num_plot+1;
plot(1:96, abi);
xlim([1 96])
ylim([0 1])
%}
%% blind deconvolution
% sonar - blind deconvolution
%{
[frame_polar_enhanced_deconv, PSF] = deconvblind(frame_polar_enhanced, ones(96), 20);
subplot(plot_rows,plot_columns,6)
imshow(frame_polar_enhanced_deconv);
subplot(plot_rows,plot_columns,7)
imshow(100*PSF);
%}
% sonar - cartesian
%{
[frame_cart, rx, ry] = polarToCart(flipud(frame_polar), data.window_start{i}, data.window_length{i}, 300);
frame_cart = fliplr(rot90(frame_cart));
subplot(1,6,5);
imshow(frame_cart);
xlabel('x');
ylabel('y');
title('Sonar (Cartesian)');
%}
% sonar (deblurred, known PSF)
%{
G = green_cart(35, 1/rx, 1/ry);
frame_cart_d = deconvreg(frame_cart, G);
subplot(1,5,5);
imshow(frame_cart_d);
%title('Sonar (deblurred)');
%}
% sonar (deblurred, unknown PSF);
%{
%G = ones(96,96);
%G = 0.5* green_cart(35, 1/rx, 1/ry) + 0.5*ones(36);
[frame_cart_d, G] = deconvblind(frame_cart,G,5);
PSF(:,:,i) = G;
subplot(1,6,5);
imshow(frame_cart_d);
subplot(1,6,6);
m = max(max(G));
imshow(G./m);
title(['Normalized PSF (max = ',num2str(m),')']);
%}
%%
suptitle( '(images marked with * are normalized)');
plot_columns = num_plot -1 ;
drawnow;
toc
end
% compute mean PSF
MPSF = mean(PSF,3);
figure()
imshow(MPSF);