-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathMSAC.m
More file actions
35 lines (32 loc) · 942 Bytes
/
MSAC.m
File metadata and controls
35 lines (32 loc) · 942 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
31
32
33
34
35
function [f,bestInliers] = MSAC(points1, points2)
%% homography
nPoints = size(points1, 1);
points1homo=points1';
points1homo(3,:)=1.0;
points2homo=points2';
points2homo(3,:)=1.0;
%%
threshold=0.01;
maxtrails = 20000;
bestDist = realmax('double');
for trails=1:maxtrails
% estimate f using random 8 points
sampleIndicies = randperm(nPoints, 8);
f = eightPoint(points1homo(:, sampleIndicies), points2homo(:, sampleIndicies));
% reprojection error
pfp = (points2homo' * f)';
pfp = pfp .* points1homo;
d = sum(pfp, 1) .^ 2;
% find inliers
inliers = coder.nullcopy(false(1, nPoints));
inliers(d<=threshold)=true;
nInliers=sum(inliers);
% MSAC metric
Dist = cast(sum(d(inliers)),'double') + threshold*(nPoints - nInliers);
if bestDist > Dist
bestDist = Dist;
bestInliers = inliers;
end
end
f = eightPoint(points1homo(:, bestInliers), points2homo(:, bestInliers));
end