-
Notifications
You must be signed in to change notification settings - Fork 1
/
heliotrope.m
93 lines (69 loc) · 2.67 KB
/
heliotrope.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
addpath('src', 'src/utils')
% Select which dataset to use
% dataset = 'trump';
dataset = 'gabe';
fprintf('Loading %s sequence\n', dataset)
if strcmp(dataset, 'gabe')
starting_img = 9;
seq = load_sequence_color('data/gabe','gjbLookAtTarget_', 0, 71, 4, 'jpg');
elseif strcmp(dataset, 'trump')
starting_img = 10;
seq = load_sequence_color('data/trump','trump_', 0, 46, 4, 'png');
end
sim_file_name = sprintf('data/%s_similarity.mat', dataset);
if exist(sim_file_name, 'file') == 2
disp('Loading similarity from cache')
load(sim_file_name, 'D')
else
disp('Calculating similarity')
D = similarity(seq);
save(sprintf('data/%s_similarity', dataset), 'D')
end
flows_file = matfile(sprintf('data/%s_flows.mat', dataset));
prompt = sprintf('Enter your starting image [%d]: ', starting_img);
selection = input(prompt);
if ~isempty(selection)
starting_img = selection;
end
fprintf('Using image %d as start\n', starting_img)
figure
imshow(seq(:, :, :, starting_img))
title('Left-click on the image to draw desired path | Right-click to add final point and finish selection | Backspace to delete previous point')
[x, y] = getline;
close;
user_path = [y, x];
n_pts = size(user_path, 1);
if n_pts < 2
close all;
error('You need to select at least 2 points')
end
fprintf("Selected %d points\n", n_pts);
G = to_graph(D);
[seq_idx, pred_pts] = calc_path(G, flows_file, seq, starting_img, user_path, false, true);
[seq_idx_trajectory, pred_trajectory] = calc_path(G, flows_file, seq, starting_img, user_path, true, true);
slow_mo_seq = synthesize_slow_motion(flows_file, seq, seq_idx_trajectory);
slow_mo_seq = draw_path_overlay(slow_mo_seq, pred_trajectory, user_path, 'scale', 0.5);
write_video(slow_mo_seq, dataset);
h = implay(slow_mo_seq, 10);
set(h.Parent, 'Name', 'Slow motion')
playback_path(seq, seq_idx, 'Without trajectory', pred_pts, user_path);
playback_path(seq, seq_idx_trajectory, 'With trajectory', pred_trajectory, user_path);
disp('Done')
function [sequence_idx, pred_points] = calc_path(G, flows_file, seq, starting_img, user_path, enable_advanced, enable_slow_motion)
n_pts = size(user_path, 1);
sequence_idx = [starting_img];
pred_points = [];
start_point = user_path(1, :);
for i = 2:n_pts
end_point = user_path(i, :);
[sequence_segment, pred_pts] = best_path(G, flows_file,...
starting_img, start_point, end_point, seq,...
'UseTrajectory', enable_advanced);
fprintf("Sequence for line segment: ");
disp(sequence_segment)
pred_points = [pred_points; pred_pts];
sequence_idx = [sequence_idx sequence_segment(2:end)];
start_point = pred_points(end, :);
starting_img = sequence_segment(end);
end
end