-
Notifications
You must be signed in to change notification settings - Fork 0
/
estSelfMotionMFunc.m
39 lines (38 loc) · 1.25 KB
/
estSelfMotionMFunc.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
function [motion, logger] = estSelfMotionMFunc(flow, f, opt)
% estSelfMotionMFunc
% flow - Image flow field.
% f - Focal length of the pinhole camera.
% opt - Options for the algorithm.
%
% RETURN
% motion - Estimated camera motion.
% logger - Logged number of iterations.
%
% DESCRIPTION
% Uses a (convex) penalty function for the optimization.
%
% Copyright (C) 2012 Florian Raudies, 04/12/2012, Boston University.
% License, GNU GPL, free software, without any warranty.
% Do not combine with any other method for robust estimation.
opt.em = 0;
opt.mfunc = 0;
opt.ransac = 0;
% Create new logger.
logger = newEstSelfMotionLogger();
% Initialize variables.
mFuncMaxIter = opt.mFuncMaxIter;
mFuncEtaW = opt.mFuncEtaW;
W = ones(size(flow.X(:)));
iter = mFuncMaxIter;
invSigmaW2 = 1 / (2 * opt.mFuncSigma^2);
rho = opt.mFuncRho;
% Iteration with adaptation of weigths.
for it = 1:mFuncMaxIter
[motion, logger] = opt.fHandle(flow, W, f, opt);
Wold = W;
Res = opt.fResidual(flow, f, motion);
W = exp(-Res * invSigmaW2) + rho;
if mean((W(:)-Wold(:)).^2) < mFuncEtaW, iter = it; break; end
end
% Store the number of iterations into the logger.
logger.mFuncIter = iter;