-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdriver_script.m
106 lines (83 loc) · 2.65 KB
/
driver_script.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
%% Load movie
clear all; close all;
movObj = VideoReader('data/IMG_0004.mov');
vidWidth = movObj.Width;
vidHeight = movObj.Height;
mov = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'), ...
'colormap', []);
% k = 1;
% while hasFrame(movObj)
% mov(k).cdata = readFrame(movObj);
% k = k+1;
% end
%% Play back
% hf = figure;
% set(hf, 'position', [150 150 vidWidth vidHeight]);
%
% movie(hf, mov, 300, movObj.FrameRate);
% Best frame at 375 (around 12-13 s)
nFrames = 900;
dsFactor = 1;
dirOut = 'data/output';
frame = imresize(read(movObj, 1), dsFactor);
[fWidth, fHeight, ~] = size(frame);
% first dimension: image index
%stack = zeros(nFrames, fWidth, fHeight, 3);
for i = 290: nFrames
frame = imresize(read(movObj, i), dsFactor);
%stack(i, :, :, :) = reshape(frame, 1, fWidth, fHeight, 3);
save(sprintf('data/frames/img%04d.mat', i), 'frame', '-v7.3');
end
%% Identify relavant images
% color_dist(frame, 'RGB', 'Best frame in RGB space');
% color_dist(eyeregion, 'RGB', 'Eye region in best frame in RGB space');
% color_dist(frame, 'HSV', 'Best frame in HSV space');
% [h, s, v] = color_dist(eyeregion, 'HSV', 'Eye region in best frame in HSV space');
% [r, g, b] = color_dist(eyeregion, 'RGB', 'Eye region in best frame in RGB space');
% figure
% hist(double(r(:)), 80)
%color_dist(oofFrame, 'HSV', 'Best frame in HSV space');
%% Identify high focus using band pass filters
%bwframe = rgb2gray(frame);
% figure
% F = fftshift(fft2(bwframe));
% magnitude = abs(F);
% imagesc(log(1 + magnitude));
% colorbar
% colormap gray
% title('Fourier transform of best frame');
% figure
% F = fftshift(fft2(rgb2gray(eyeregion)));
% magnitude = abs(F);
% imagesc(log(1 + magnitude));
% colorbar
% colormap gray
% title('Fourier transform of eye region');
% out of focus
% figure
% oofFrame = read(movObj, 700); %imshow(oofFrame(504: 925, 370:718))
% imshow(oofFrame);
% F = fftshift(fft2( rgb2gray(oofFrame)));
% magnitude = abs(F);
% imagesc(log(1 + magnitude));
% colorbar
% colormap gray
% title('Fourier transform of out of focus frame');
% figure
% F = fftshift(fft2(rgb2gray(oofFrame(343: 575, 674: 929, :))));
% magnitude = abs(F);
% imagesc(log(1 + magnitude));
% colorbar
% colormap gray
% title('Fourier transform of out of focus eye region');
%% Motion
% frame1 = read(movObj, 376);
% [ resultImg, displacement ] = optical_flow_translation( double(frame), double(frame1), [10, 1000; 10, 1900] );
%% Comparison
% frameIr = read(movObj, 800);
% imshow(frameIr);
% color_dist(frame, 'HSV', 'Best frame in HSV space');
% [h, s, v] = color_dist(eyeregion, 'HSV', 'Eye region in best frame in HSV space');
%
% frameIr = read(movObj, 600);
% imshow(frameIr);