-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.m
More file actions
59 lines (40 loc) · 1.54 KB
/
example.m
File metadata and controls
59 lines (40 loc) · 1.54 KB
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
%% clean up
clear all;close all;clc;
addpath(genpath(cd));
%% How to:
% make sure you have downloaded a copy of flexBox from www.flexbox.im and
% this copy is in your MATALB path. Moreover, you should compile the
% C++-module for runtime reasons!
%
% Simply edit the following section for different motion estimation models
%% parameters
dataTerm = 'L1'; %set to L1 or L2
regularizerTerm = 'L2'; %set to L2, L1 or Huber
weight = 0.01; %regulates the weight of the regularizer: higher values generate smoother results
tol = 1e-5; %error tolerance. Don't change
%%
image1 = imread(['data',filesep,'frame10.png']);
image2 = imread(['data',filesep,'frame11.png']);
if (size(image1,3)>1)
image1 = rgb2gray(image1);
image2 = rgb2gray(image2);
end
image1 = im2double(image1);
image2 = im2double(image2);
%resize image
image1 = imresize(image1,1);
image2 = imresize(image2,1);
flowGT = readFlowFile(['data',filesep,'flow10.flo']);
flowGT(abs(flowGT)>1e2) = 0;
figure(99);clf;imagesc(flowToColorV2(cat(3,flowGT(:,:,1),flowGT(:,:,2))));
%% assemble input sequence
u = cat(3,image1,image2);
%% create algorithm and solve problem
motionEstimator = motionEstimatorClass(u,tol,weight,'dataTerm',dataTerm,'regularizerTerm',regularizerTerm);
motionEstimator.init;
motionEstimator.verbose = 2;
tic;motionEstimator.runPyramid;toc;
%% get result
v = motionEstimator.getResult; %get result from class
v = squeeze(v(:,:,1,:)); %extract flow between first and second frame and remove singleton dimension
figure(1);clf;imagesc(flowToColorV2(cat(3,v(:,:,1),v(:,:,2))));