-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowIter.m
More file actions
31 lines (24 loc) · 983 Bytes
/
Copy pathFlowIter.m
File metadata and controls
31 lines (24 loc) · 983 Bytes
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
function [ du, dv ] = FlowIter( height, width, laplacian, dt, dx, dy, options)
% img1 and img2 assumed to be grayscale floating point images
% Some little helper functions
function [ sparseM ] = diagSparse( M )
Mrow = reshape(M, [], 1);
sparseM = spdiags(Mrow, 0, length(Mrow), length(Mrow));
end
alpha = options.alpha;
% Compute linear flow operator
A = [diagSparse(dx.*dx) + alpha * laplacian, diagSparse(dx .* dy);
diagSparse(dx .* dy), diagSparse(dy.^2) + alpha * laplacian];
b = -[reshape(dx .* dt, [], 1); ...
reshape(dy .* dt, [], 1)];
deltaFlow = A \ b; % solve linear equation
du = reshape(deltaFlow(1:height*width, :), height, width);
dv = reshape(deltaFlow(height*width+1:2*height*width, :), height, width);
% limit the incremental flow
if options.limit
du(du > 1) = 1;
du(du < -1) = -1;
dv(dv > 1) = 1;
dv(dv < -1) = -1;
end
end